@rio-cloud/rio-uikit 2.3.0-beta.2 → 2.3.0-beta.3
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/Marker.js +9 -5
- package/components/analyticsAnalysisOverlay/AnalyticsAnalysisBanner.d.ts +38 -3
- package/components/analyticsAnalysisOverlay/AnalyticsAnalysisBanner.js +104 -109
- package/components/analyticsAnalysisOverlay/AnalyticsAnalysisBanner.js.map +1 -1
- package/components/analyticsAnalysisOverlay/AnalyticsAnalysisOverlay.d.ts +24 -5
- package/components/analyticsAnalysisOverlay/AnalyticsAnalysisOverlay.js +60 -56
- package/components/analyticsAnalysisOverlay/AnalyticsAnalysisOverlay.js.map +1 -1
- package/components/datepicker/DayPicker.js +72 -70
- package/components/datepicker/DayPicker.js.map +1 -1
- package/components/datepicker/DayPickerDropdown.d.ts +1 -0
- package/components/datepicker/DayPickerDropdown.js +61 -48
- package/components/datepicker/DayPickerDropdown.js.map +1 -1
- package/components/datepicker/useStackedDayPickerCalendars.js +26 -26
- package/components/datepicker/useStackedDayPickerCalendars.js.map +1 -1
- package/components/listMenu/ListMenu.d.ts +8 -0
- package/components/listMenu/ListMenu.js +74 -66
- package/components/listMenu/ListMenu.js.map +1 -1
- package/components/map/components/Map.js +189 -157
- package/components/map/components/Map.js.map +1 -1
- package/components/map/components/MapContext.d.ts +1 -0
- package/components/map/components/MapContext.js +8 -7
- package/components/map/components/MapContext.js.map +1 -1
- package/components/map/components/features/Route.d.ts +65 -1
- package/components/map/components/features/Route.js +184 -98
- package/components/map/components/features/Route.js.map +1 -1
- package/components/map/components/features/basics/Marker.d.ts +21 -1
- package/components/map/components/features/basics/Marker.js +99 -40
- package/components/map/components/features/basics/Marker.js.map +1 -1
- package/components/map/components/features/basics/Polygon.d.ts +24 -1
- package/components/map/components/features/basics/Polygon.js +72 -19
- package/components/map/components/features/basics/Polygon.js.map +1 -1
- package/components/map/components/features/basics/Polyline.d.ts +29 -0
- package/components/map/components/features/basics/Polyline.js +69 -39
- package/components/map/components/features/basics/Polyline.js.map +1 -1
- package/components/map/components/features/layers/MarkerLayer.js +8 -8
- package/components/map/components/features/layers/MarkerLayer.js.map +1 -1
- package/components/map/components/features/layers/clustering/SimpleClusterLayer.js +13 -6
- package/components/map/components/features/layers/clustering/SimpleClusterLayer.js.map +1 -1
- package/components/map/utils/clustering.d.ts +1 -1
- package/components/map/utils/clustering.js +30 -30
- package/components/map/utils/clustering.js.map +1 -1
- package/components/map/utils/mapTypes.d.ts +135 -0
- package/components/map/utils/mapTypes.js.map +1 -1
- package/components/mapMarker/ClusterMapMarker.d.ts +2 -0
- package/components/mapMarker/ClusterMapMarker.js.map +1 -1
- package/components/mapMarker/SingleMapMarker.d.ts +2 -0
- package/components/mapMarker/SingleMapMarker.js.map +1 -1
- package/components/selects/ClearButton.js +9 -7
- package/components/selects/ClearButton.js.map +1 -1
- package/components/table/Table.js +208 -205
- package/components/table/Table.js.map +1 -1
- package/components/table/Table.types.d.ts +13 -4
- package/components/table/TableColumn.d.ts +8 -1
- package/components/table/TableColumn.js +66 -64
- package/components/table/TableColumn.js.map +1 -1
- package/components/table/TableExpandedRow.js +11 -11
- package/components/table/TableExpandedRow.js.map +1 -1
- package/components/table/TableHeader.d.ts +17 -0
- package/components/table/TableHeader.js +89 -76
- package/components/table/TableHeader.js.map +1 -1
- package/components/table/TableHeaderColumn.d.ts +11 -1
- package/components/table/TableHeaderColumn.js +63 -58
- package/components/table/TableHeaderColumn.js.map +1 -1
- package/components/table/TableRow.d.ts +6 -0
- package/components/table/TableRow.js +49 -48
- package/components/table/TableRow.js.map +1 -1
- package/components/table/context/TableLayoutContext.d.ts +1 -0
- package/components/table/context/TableLayoutContext.js.map +1 -1
- package/components/table/layout/useHorizontalSectionSync.d.ts +2 -1
- package/components/table/layout/useHorizontalSectionSync.js +32 -31
- package/components/table/layout/useHorizontalSectionSync.js.map +1 -1
- package/components/table/layout/useTableLayout.d.ts +2 -1
- package/components/table/layout/useTableLayout.js +37 -30
- package/components/table/layout/useTableLayout.js.map +1 -1
- package/components/table/render/header/TableDraggableHeaderCell.js +38 -36
- package/components/table/render/header/TableDraggableHeaderCell.js.map +1 -1
- package/components/table/render/header/TableHeader.types.d.ts +2 -0
- package/components/table/render/header/TableHeaderCellContent.js +16 -16
- package/components/table/render/header/TableHeaderCellContent.js.map +1 -1
- package/components/table/render/header/TableStaticHeaderCell.js +31 -29
- package/components/table/render/header/TableStaticHeaderCell.js.map +1 -1
- package/components/table/render/header/resolveHeaderCellClassName.d.ts +1 -0
- package/components/table/render/header/resolveHeaderCellClassName.js +10 -9
- package/components/table/render/header/resolveHeaderCellClassName.js.map +1 -1
- package/components/table/runtime/useResolvedRenderColumns.d.ts +4 -4
- package/components/table/runtime/useResolvedRenderColumns.js +13 -13
- package/components/table/runtime/useResolvedRenderColumns.js.map +1 -1
- package/components/table/runtime/useResolvedRenderHeader.d.ts +1 -1
- package/components/table/runtime/useResolvedRenderHeader.js.map +1 -1
- package/hooks/useDraggableElement.d.ts +27 -5
- package/hooks/useDraggableElement.js +100 -23
- package/hooks/useDraggableElement.js.map +1 -1
- package/hooks/usePopperDropdown.d.ts +1 -0
- package/hooks/usePopperDropdown.js +15 -12
- package/hooks/usePopperDropdown.js.map +1 -1
- package/package.json +1 -1
- package/utils/analytics/createAnalyticsOverlayTooltip.js.map +1 -1
- package/utils/init/initConfig.js +5 -5
- package/utils/init/initConfig.js.map +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { getVerticalAlignClassName as
|
|
3
|
-
const n = (e,
|
|
4
|
-
const { isDraggable: t, isDragging: i, isResizable: r, isStickyLeftColumn: s } =
|
|
5
|
-
return
|
|
1
|
+
import b from "../../../../utils/classNames.js";
|
|
2
|
+
import { getVerticalAlignClassName as d, getHorizontalAlignClassName as g } from "../../shared/getAlignClassName.js";
|
|
3
|
+
const n = (e, l, a) => {
|
|
4
|
+
const { isDraggable: t, isDragging: i, isResizable: r, isStickyLeftColumn: s, isStickyRightColumn: o } = a;
|
|
5
|
+
return b(
|
|
6
6
|
"table-head-cell",
|
|
7
7
|
e.sortable && "table-head-cell-sortable",
|
|
8
8
|
t && "table-head-cell-draggable",
|
|
9
9
|
i && "table-head-cell-dragging",
|
|
10
10
|
r && "table-head-cell-resizable",
|
|
11
11
|
s && "table-head-cell-sticky-left-column",
|
|
12
|
-
|
|
13
|
-
e.
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
o && "table-head-cell-sticky-right-column",
|
|
13
|
+
e.columnStart + e.colSpan - 1 < l.totalColumnCount && "table-head-cell-has-column-divider",
|
|
14
|
+
e.rowStart + e.rowSpan - 1 < l.rowCount && "table-head-cell-has-row-divider",
|
|
15
|
+
g(e.horizontalAlign),
|
|
16
|
+
d(e.verticalAlign),
|
|
16
17
|
e.hideOnMobile && "table-hide-mobile",
|
|
17
18
|
e.headerClassName
|
|
18
19
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveHeaderCellClassName.js","sources":["../../../../../src/components/table/render/header/resolveHeaderCellClassName.ts"],"sourcesContent":["import classNames from '../../../../utils/classNames';\nimport { getHorizontalAlignClassName, getVerticalAlignClassName } from '../../shared/getAlignClassName';\nimport type { TableRowData } from '../../Table.types';\nimport type { HeaderColumn } from './TableHeader.types';\n\nexport const resolveHeaderCellClassName = (\n column: HeaderColumn<TableRowData>,\n header: NonNullable<{ columns: HeaderColumn<TableRowData>[]; rowCount: number; totalColumnCount: number }>,\n options: {\n isDraggable?: boolean;\n isDragging?: boolean;\n isResizable: boolean;\n isStickyLeftColumn?: boolean;\n }\n) => {\n const { isDraggable, isDragging, isResizable, isStickyLeftColumn } = options;\n\n return classNames(\n 'table-head-cell',\n column.sortable && 'table-head-cell-sortable',\n isDraggable && 'table-head-cell-draggable',\n isDragging && 'table-head-cell-dragging',\n isResizable && 'table-head-cell-resizable',\n isStickyLeftColumn && 'table-head-cell-sticky-left-column',\n column.columnStart + column.colSpan - 1 < header.totalColumnCount && 'table-head-cell-has-column-divider',\n column.rowStart + column.rowSpan - 1 < header.rowCount && 'table-head-cell-has-row-divider',\n getHorizontalAlignClassName(column.horizontalAlign),\n getVerticalAlignClassName(column.verticalAlign),\n column.hideOnMobile && 'table-hide-mobile',\n column.headerClassName\n );\n};\n"],"names":["resolveHeaderCellClassName","column","header","options","isDraggable","isDragging","isResizable","isStickyLeftColumn","classNames","getHorizontalAlignClassName","getVerticalAlignClassName"],"mappings":";;AAKO,MAAMA,IAA6B,CACtCC,GACAC,GACAC,
|
|
1
|
+
{"version":3,"file":"resolveHeaderCellClassName.js","sources":["../../../../../src/components/table/render/header/resolveHeaderCellClassName.ts"],"sourcesContent":["import classNames from '../../../../utils/classNames';\nimport { getHorizontalAlignClassName, getVerticalAlignClassName } from '../../shared/getAlignClassName';\nimport type { TableRowData } from '../../Table.types';\nimport type { HeaderColumn } from './TableHeader.types';\n\nexport const resolveHeaderCellClassName = (\n column: HeaderColumn<TableRowData>,\n header: NonNullable<{ columns: HeaderColumn<TableRowData>[]; rowCount: number; totalColumnCount: number }>,\n options: {\n isDraggable?: boolean;\n isDragging?: boolean;\n isResizable: boolean;\n isStickyLeftColumn?: boolean;\n isStickyRightColumn?: boolean;\n }\n) => {\n const { isDraggable, isDragging, isResizable, isStickyLeftColumn, isStickyRightColumn } = options;\n\n return classNames(\n 'table-head-cell',\n column.sortable && 'table-head-cell-sortable',\n isDraggable && 'table-head-cell-draggable',\n isDragging && 'table-head-cell-dragging',\n isResizable && 'table-head-cell-resizable',\n isStickyLeftColumn && 'table-head-cell-sticky-left-column',\n isStickyRightColumn && 'table-head-cell-sticky-right-column',\n column.columnStart + column.colSpan - 1 < header.totalColumnCount && 'table-head-cell-has-column-divider',\n column.rowStart + column.rowSpan - 1 < header.rowCount && 'table-head-cell-has-row-divider',\n getHorizontalAlignClassName(column.horizontalAlign),\n getVerticalAlignClassName(column.verticalAlign),\n column.hideOnMobile && 'table-hide-mobile',\n column.headerClassName\n );\n};\n"],"names":["resolveHeaderCellClassName","column","header","options","isDraggable","isDragging","isResizable","isStickyLeftColumn","isStickyRightColumn","classNames","getHorizontalAlignClassName","getVerticalAlignClassName"],"mappings":";;AAKO,MAAMA,IAA6B,CACtCC,GACAC,GACAC,MAOC;AACD,QAAM,EAAE,aAAAC,GAAa,YAAAC,GAAY,aAAAC,GAAa,oBAAAC,GAAoB,qBAAAC,MAAwBL;AAE1F,SAAOM;AAAA,IACH;AAAA,IACAR,EAAO,YAAY;AAAA,IACnBG,KAAe;AAAA,IACfC,KAAc;AAAA,IACdC,KAAe;AAAA,IACfC,KAAsB;AAAA,IACtBC,KAAuB;AAAA,IACvBP,EAAO,cAAcA,EAAO,UAAU,IAAIC,EAAO,oBAAoB;AAAA,IACrED,EAAO,WAAWA,EAAO,UAAU,IAAIC,EAAO,YAAY;AAAA,IAC1DQ,EAA4BT,EAAO,eAAe;AAAA,IAClDU,EAA0BV,EAAO,aAAa;AAAA,IAC9CA,EAAO,gBAAgB;AAAA,IACvBA,EAAO;AAAA,EAAA;AAEf;"}
|
|
@@ -19,20 +19,20 @@ export type UseResolvedRenderColumnsReturn<RowType extends TableRowData> = {
|
|
|
19
19
|
handleColumnResizeStart: ReturnType<typeof useResizableColumns<RowType>>['handleColumnResizeStart'];
|
|
20
20
|
lastResizableColumnKey?: string;
|
|
21
21
|
resettableColumnKeys: Set<string>;
|
|
22
|
-
|
|
22
|
+
renderDataColumns: RenderHeaderColumn<RowType>[];
|
|
23
23
|
resizeColumnsEnabled: boolean;
|
|
24
24
|
resolvedRenderColumns: RenderHeaderColumn<RowType>[];
|
|
25
25
|
resizedColumns: ReturnType<typeof useResizableColumns<RowType>>['resizedColumns'];
|
|
26
26
|
};
|
|
27
27
|
/**
|
|
28
|
-
* Resolves the
|
|
28
|
+
* Resolves the actual data columns that drive layout and column behavior.
|
|
29
29
|
*
|
|
30
30
|
* Header registration can contain grouped header cells, multi-row headers, and
|
|
31
31
|
* other metadata that is useful for rendering, but drag, resize, sticky layout,
|
|
32
|
-
* and body/footer cell placement ultimately need a flat list of
|
|
32
|
+
* and body/footer cell placement ultimately need a flat list of actual data columns.
|
|
33
33
|
*
|
|
34
34
|
* This hook therefore:
|
|
35
|
-
* - narrows registered header cells down to
|
|
35
|
+
* - narrows registered header cells down to single-column data headers with a stable `columnKey`
|
|
36
36
|
* - applies column reordering
|
|
37
37
|
* - applies resized widths
|
|
38
38
|
* - exposes a normalized column map for body/footer cell lookup
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMemo as l } from "react";
|
|
2
|
-
import { useDraggableColumns as
|
|
3
|
-
import { useResizableColumns as
|
|
2
|
+
import { useDraggableColumns as A } from "../layout/useDraggableColumns.js";
|
|
3
|
+
import { useResizableColumns as L } from "../layout/useResizableColumns.js";
|
|
4
4
|
const B = (m) => {
|
|
5
5
|
const { columnOrder: g, onColumnOrderChange: C, onColumnResize: y, renderHeaderColumns: t, viewType: d } = m, i = l(
|
|
6
6
|
() => t.flatMap(
|
|
@@ -28,18 +28,18 @@ const B = (m) => {
|
|
|
28
28
|
sortable: e.sortable
|
|
29
29
|
})),
|
|
30
30
|
[i]
|
|
31
|
-
), o = d === "TABLE" && n.filter((e) => e.draggable === !0).length > 1, { draggableColumnKeys: R, handleColumnDragEnd: p, orderedColumns: b } =
|
|
31
|
+
), o = d === "TABLE" && n.filter((e) => e.draggable === !0).length > 1, { draggableColumnKeys: R, handleColumnDragEnd: p, orderedColumns: b } = A({
|
|
32
32
|
columns: n,
|
|
33
33
|
columnOrder: g,
|
|
34
34
|
enabled: o,
|
|
35
35
|
onColumnOrderChange: C
|
|
36
36
|
}), h = d === "TABLE" && b.some((e) => e.resizeable === !0), {
|
|
37
37
|
handleColumnResizeReset: K,
|
|
38
|
-
handleColumnResizeStart:
|
|
39
|
-
lastResizableColumnKey:
|
|
40
|
-
resettableColumnKeys:
|
|
38
|
+
handleColumnResizeStart: M,
|
|
39
|
+
lastResizableColumnKey: W,
|
|
40
|
+
resettableColumnKeys: f,
|
|
41
41
|
resizedColumns: r
|
|
42
|
-
} =
|
|
42
|
+
} = L({
|
|
43
43
|
columns: b,
|
|
44
44
|
enabled: h,
|
|
45
45
|
onColumnResize: y
|
|
@@ -87,21 +87,21 @@ const B = (m) => {
|
|
|
87
87
|
])
|
|
88
88
|
),
|
|
89
89
|
[s]
|
|
90
|
-
),
|
|
90
|
+
), x = l(
|
|
91
91
|
() => new Map(s.map((e, a) => [e.columnKey, a])),
|
|
92
92
|
[s]
|
|
93
93
|
);
|
|
94
94
|
return {
|
|
95
95
|
columnDefinitionsByKey: w,
|
|
96
|
-
columnIndexByKey:
|
|
96
|
+
columnIndexByKey: x,
|
|
97
97
|
draggableColumnKeys: R,
|
|
98
98
|
draggableColumnsEnabled: o,
|
|
99
99
|
handleColumnDragEnd: p,
|
|
100
100
|
handleColumnResizeReset: K,
|
|
101
|
-
handleColumnResizeStart:
|
|
102
|
-
lastResizableColumnKey:
|
|
103
|
-
resettableColumnKeys:
|
|
104
|
-
|
|
101
|
+
handleColumnResizeStart: M,
|
|
102
|
+
lastResizableColumnKey: W,
|
|
103
|
+
resettableColumnKeys: f,
|
|
104
|
+
renderDataColumns: i,
|
|
105
105
|
resizeColumnsEnabled: h,
|
|
106
106
|
resolvedRenderColumns: s,
|
|
107
107
|
resizedColumns: r
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useResolvedRenderColumns.js","sources":["../../../../src/components/table/runtime/useResolvedRenderColumns.ts"],"sourcesContent":["import { useMemo } from 'react';\n\nimport type { RenderHeaderColumn } from '../context/TableRenderContext';\nimport { useDraggableColumns } from '../layout/useDraggableColumns';\nimport { useResizableColumns } from '../layout/useResizableColumns';\nimport type { TableColumnDefinition, TableProps, TableRowData } from '../Table.types';\n\ntype UseResolvedRenderColumnsProps<RowType extends TableRowData> = {\n columnOrder: TableProps<RowType>['columnOrder'];\n onColumnOrderChange: TableProps<RowType>['onColumnOrderChange'];\n onColumnResize: TableProps<RowType>['onColumnResize'];\n renderHeaderColumns: RenderHeaderColumn<RowType>[];\n viewType: TableProps<RowType>['viewType'];\n};\n\nexport type UseResolvedRenderColumnsReturn<RowType extends TableRowData> = {\n columnDefinitionsByKey: Map<string, TableColumnDefinition<RowType>>;\n columnIndexByKey: Map<string, number>;\n draggableColumnKeys?: string[];\n draggableColumnsEnabled: boolean;\n handleColumnDragEnd: ReturnType<typeof useDraggableColumns>['handleColumnDragEnd'];\n handleColumnResizeReset: ReturnType<typeof useResizableColumns<RowType>>['handleColumnResizeReset'];\n handleColumnResizeStart: ReturnType<typeof useResizableColumns<RowType>>['handleColumnResizeStart'];\n lastResizableColumnKey?: string;\n resettableColumnKeys: Set<string>;\n renderLeafColumns: RenderHeaderColumn<RowType>[];\n resizeColumnsEnabled: boolean;\n resolvedRenderColumns: RenderHeaderColumn<RowType>[];\n resizedColumns: ReturnType<typeof useResizableColumns<RowType>>['resizedColumns'];\n};\n\n/**\n * Resolves the leaf-level table columns that drive layout and column behavior.\n *\n * Header registration can contain grouped header cells, multi-row headers, and\n * other metadata that is useful for rendering, but drag, resize, sticky layout,\n * and body/footer cell placement ultimately need a flat list of leaf columns.\n *\n * This hook therefore:\n * - narrows registered header cells down to leaf columns with a stable `columnKey`\n * - applies column reordering\n * - applies resized widths\n * - exposes a normalized column map for body/footer cell lookup\n *\n * `Table` uses this as the canonical column model for the rest of the render pass.\n */\nconst useResolvedRenderColumns = <RowType extends TableRowData>(\n props: UseResolvedRenderColumnsProps<RowType>\n): UseResolvedRenderColumnsReturn<RowType> => {\n const { columnOrder, onColumnOrderChange, onColumnResize, renderHeaderColumns, viewType } = props;\n\n // Only leaf header cells represent actual data columns. Group headers span\n // other columns and are part of the header layout, but not the column model\n // used by body/footer cells or drag/resize behavior.\n const renderLeafColumns = useMemo(\n () =>\n renderHeaderColumns.flatMap(column =>\n column.columnKey && column.colSpan === 1\n ? [\n {\n ...column,\n columnKey: column.columnKey,\n },\n ]\n : []\n ),\n [renderHeaderColumns]\n );\n\n const baseRenderColumnDefinitions = useMemo(\n () =>\n renderLeafColumns.map(column => ({\n key: column.columnKey,\n label: column.columnKey,\n mobileLabel: column.mobileLabel,\n width: column.width,\n minResizeWidth: column.minResizeWidth,\n maxResizeWidth: column.maxResizeWidth,\n draggable: column.draggable,\n resizeable: column.resizeable,\n horizontalAlign: column.horizontalAlign,\n headerClassName: column.headerClassName,\n hideOnMobile: column.hideOnMobile,\n sortable: column.sortable,\n })),\n [renderLeafColumns]\n );\n\n const draggableColumnsEnabled =\n viewType === 'TABLE' && baseRenderColumnDefinitions.filter(column => column.draggable === true).length > 1;\n const { draggableColumnKeys, handleColumnDragEnd, orderedColumns } = useDraggableColumns({\n columns: baseRenderColumnDefinitions,\n columnOrder,\n enabled: draggableColumnsEnabled,\n onColumnOrderChange,\n });\n\n const resizeColumnsEnabled = viewType === 'TABLE' && orderedColumns.some(column => column.resizeable === true);\n const {\n handleColumnResizeReset,\n handleColumnResizeStart,\n lastResizableColumnKey,\n resettableColumnKeys,\n resizedColumns,\n } = useResizableColumns({\n columns: orderedColumns,\n enabled: resizeColumnsEnabled,\n onColumnResize,\n });\n\n // Merge reordered/resized column behavior back into the registered leaf\n // columns so the rest of the table can render from one normalized shape.\n const resolvedRenderColumns = useMemo(() => {\n const renderColumnsByKey = new Map(renderLeafColumns.map(column => [column.columnKey, column] as const));\n\n return resizedColumns.flatMap(column => {\n const renderColumn = renderColumnsByKey.get(column.key);\n\n return renderColumn\n ? [\n {\n ...renderColumn,\n width: column.width,\n minResizeWidth: column.minResizeWidth,\n maxResizeWidth: column.maxResizeWidth,\n draggable: column.draggable,\n resizeable: column.resizeable,\n horizontalAlign: column.horizontalAlign,\n headerClassName: column.headerClassName,\n hideOnMobile: column.hideOnMobile,\n sortable: column.sortable,\n },\n ]\n : [];\n });\n }, [renderLeafColumns, resizedColumns]);\n\n // Body and footer cells resolve their column metadata by `columnKey`, so keep\n // an efficient lookup map next to the ordered column array.\n const columnDefinitionsByKey = useMemo(\n () =>\n new Map<string, TableColumnDefinition<RowType>>(\n resolvedRenderColumns.map(column => [\n column.columnKey,\n {\n key: column.columnKey,\n label: column.label,\n mobileLabel: column.mobileLabel,\n icon: column.icon,\n filter: column.filter,\n hideLabel: column.hideLabel,\n width: column.width,\n minResizeWidth: column.minResizeWidth,\n maxResizeWidth: column.maxResizeWidth,\n draggable: column.draggable,\n resizeable: column.resizeable,\n horizontalAlign: column.horizontalAlign,\n className: undefined,\n headerClassName: column.headerClassName,\n hideOnMobile: column.hideOnMobile,\n sortable: column.sortable,\n },\n ])\n ),\n [resolvedRenderColumns]\n );\n const columnIndexByKey = useMemo(\n () => new Map(resolvedRenderColumns.map((column, index) => [column.columnKey, index] as const)),\n [resolvedRenderColumns]\n );\n\n return {\n columnDefinitionsByKey,\n columnIndexByKey,\n draggableColumnKeys,\n draggableColumnsEnabled,\n handleColumnDragEnd,\n handleColumnResizeReset,\n handleColumnResizeStart,\n lastResizableColumnKey,\n resettableColumnKeys,\n renderLeafColumns,\n resizeColumnsEnabled,\n resolvedRenderColumns,\n resizedColumns,\n };\n};\n\nexport default useResolvedRenderColumns;\n"],"names":["useResolvedRenderColumns","props","columnOrder","onColumnOrderChange","onColumnResize","renderHeaderColumns","viewType","renderLeafColumns","useMemo","column","baseRenderColumnDefinitions","draggableColumnsEnabled","draggableColumnKeys","handleColumnDragEnd","orderedColumns","useDraggableColumns","resizeColumnsEnabled","handleColumnResizeReset","handleColumnResizeStart","lastResizableColumnKey","resettableColumnKeys","resizedColumns","useResizableColumns","resolvedRenderColumns","renderColumnsByKey","renderColumn","columnDefinitionsByKey","columnIndexByKey","index"],"mappings":";;;AA8CA,MAAMA,IAA2B,CAC7BC,MAC0C;AAC1C,QAAM,EAAE,aAAAC,GAAa,qBAAAC,GAAqB,gBAAAC,GAAgB,qBAAAC,GAAqB,UAAAC,MAAaL,GAKtFM,IAAoBC;AAAA,IACtB,MACIH,E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A,IAC9F,CAACL,CAAqB;AAAA,EAAA;AAG1B,SAAO;AAAA,IACH,wBAAAG;AAAA,IACA,kBAAAC;AAAA,IACA,qBAAAf;AAAA,IACA,yBAAAD;AAAA,IACA,qBAAAE;AAAA,IACA,yBAAAI;AAAA,IACA,yBAAAC;AAAA,IACA,wBAAAC;AAAA,IACA,sBAAAC;AAAA,IACA,mBAAAb;AAAA,IACA,sBAAAS;AAAA,IACA,uBAAAO;AAAA,IACA,gBAAAF;AAAA,EAAA;AAER;"}
|
|
1
|
+
{"version":3,"file":"useResolvedRenderColumns.js","sources":["../../../../src/components/table/runtime/useResolvedRenderColumns.ts"],"sourcesContent":["import { useMemo } from 'react';\n\nimport type { RenderHeaderColumn } from '../context/TableRenderContext';\nimport { useDraggableColumns } from '../layout/useDraggableColumns';\nimport { useResizableColumns } from '../layout/useResizableColumns';\nimport type { TableColumnDefinition, TableProps, TableRowData } from '../Table.types';\n\ntype UseResolvedRenderColumnsProps<RowType extends TableRowData> = {\n columnOrder: TableProps<RowType>['columnOrder'];\n onColumnOrderChange: TableProps<RowType>['onColumnOrderChange'];\n onColumnResize: TableProps<RowType>['onColumnResize'];\n renderHeaderColumns: RenderHeaderColumn<RowType>[];\n viewType: TableProps<RowType>['viewType'];\n};\n\nexport type UseResolvedRenderColumnsReturn<RowType extends TableRowData> = {\n columnDefinitionsByKey: Map<string, TableColumnDefinition<RowType>>;\n columnIndexByKey: Map<string, number>;\n draggableColumnKeys?: string[];\n draggableColumnsEnabled: boolean;\n handleColumnDragEnd: ReturnType<typeof useDraggableColumns>['handleColumnDragEnd'];\n handleColumnResizeReset: ReturnType<typeof useResizableColumns<RowType>>['handleColumnResizeReset'];\n handleColumnResizeStart: ReturnType<typeof useResizableColumns<RowType>>['handleColumnResizeStart'];\n lastResizableColumnKey?: string;\n resettableColumnKeys: Set<string>;\n renderDataColumns: RenderHeaderColumn<RowType>[];\n resizeColumnsEnabled: boolean;\n resolvedRenderColumns: RenderHeaderColumn<RowType>[];\n resizedColumns: ReturnType<typeof useResizableColumns<RowType>>['resizedColumns'];\n};\n\n/**\n * Resolves the actual data columns that drive layout and column behavior.\n *\n * Header registration can contain grouped header cells, multi-row headers, and\n * other metadata that is useful for rendering, but drag, resize, sticky layout,\n * and body/footer cell placement ultimately need a flat list of actual data columns.\n *\n * This hook therefore:\n * - narrows registered header cells down to single-column data headers with a stable `columnKey`\n * - applies column reordering\n * - applies resized widths\n * - exposes a normalized column map for body/footer cell lookup\n *\n * `Table` uses this as the canonical column model for the rest of the render pass.\n */\nconst useResolvedRenderColumns = <RowType extends TableRowData>(\n props: UseResolvedRenderColumnsProps<RowType>\n): UseResolvedRenderColumnsReturn<RowType> => {\n const { columnOrder, onColumnOrderChange, onColumnResize, renderHeaderColumns, viewType } = props;\n\n // Only single-column header cells represent actual data columns. Group headers span\n // other columns and are part of the header layout, but not the column model\n // used by body/footer cells or drag/resize behavior.\n const renderDataColumns = useMemo(\n () =>\n renderHeaderColumns.flatMap(column =>\n column.columnKey && column.colSpan === 1\n ? [\n {\n ...column,\n columnKey: column.columnKey,\n },\n ]\n : []\n ),\n [renderHeaderColumns]\n );\n\n const baseRenderColumnDefinitions = useMemo(\n () =>\n renderDataColumns.map(column => ({\n key: column.columnKey,\n label: column.columnKey,\n mobileLabel: column.mobileLabel,\n width: column.width,\n minResizeWidth: column.minResizeWidth,\n maxResizeWidth: column.maxResizeWidth,\n draggable: column.draggable,\n resizeable: column.resizeable,\n horizontalAlign: column.horizontalAlign,\n headerClassName: column.headerClassName,\n hideOnMobile: column.hideOnMobile,\n sortable: column.sortable,\n })),\n [renderDataColumns]\n );\n\n const draggableColumnsEnabled =\n viewType === 'TABLE' && baseRenderColumnDefinitions.filter(column => column.draggable === true).length > 1;\n const { draggableColumnKeys, handleColumnDragEnd, orderedColumns } = useDraggableColumns({\n columns: baseRenderColumnDefinitions,\n columnOrder,\n enabled: draggableColumnsEnabled,\n onColumnOrderChange,\n });\n\n const resizeColumnsEnabled = viewType === 'TABLE' && orderedColumns.some(column => column.resizeable === true);\n const {\n handleColumnResizeReset,\n handleColumnResizeStart,\n lastResizableColumnKey,\n resettableColumnKeys,\n resizedColumns,\n } = useResizableColumns({\n columns: orderedColumns,\n enabled: resizeColumnsEnabled,\n onColumnResize,\n });\n\n // Merge reordered/resized column behavior back into the registered data\n // columns so the rest of the table can render from one normalized shape.\n const resolvedRenderColumns = useMemo(() => {\n const renderColumnsByKey = new Map(renderDataColumns.map(column => [column.columnKey, column] as const));\n\n return resizedColumns.flatMap(column => {\n const renderColumn = renderColumnsByKey.get(column.key);\n\n return renderColumn\n ? [\n {\n ...renderColumn,\n width: column.width,\n minResizeWidth: column.minResizeWidth,\n maxResizeWidth: column.maxResizeWidth,\n draggable: column.draggable,\n resizeable: column.resizeable,\n horizontalAlign: column.horizontalAlign,\n headerClassName: column.headerClassName,\n hideOnMobile: column.hideOnMobile,\n sortable: column.sortable,\n },\n ]\n : [];\n });\n }, [renderDataColumns, resizedColumns]);\n\n // Body and footer cells resolve their column metadata by `columnKey`, so keep\n // an efficient lookup map next to the ordered column array.\n const columnDefinitionsByKey = useMemo(\n () =>\n new Map<string, TableColumnDefinition<RowType>>(\n resolvedRenderColumns.map(column => [\n column.columnKey,\n {\n key: column.columnKey,\n label: column.label,\n mobileLabel: column.mobileLabel,\n icon: column.icon,\n filter: column.filter,\n hideLabel: column.hideLabel,\n width: column.width,\n minResizeWidth: column.minResizeWidth,\n maxResizeWidth: column.maxResizeWidth,\n draggable: column.draggable,\n resizeable: column.resizeable,\n horizontalAlign: column.horizontalAlign,\n className: undefined,\n headerClassName: column.headerClassName,\n hideOnMobile: column.hideOnMobile,\n sortable: column.sortable,\n },\n ])\n ),\n [resolvedRenderColumns]\n );\n const columnIndexByKey = useMemo(\n () => new Map(resolvedRenderColumns.map((column, index) => [column.columnKey, index] as const)),\n [resolvedRenderColumns]\n );\n\n return {\n columnDefinitionsByKey,\n columnIndexByKey,\n draggableColumnKeys,\n draggableColumnsEnabled,\n handleColumnDragEnd,\n handleColumnResizeReset,\n handleColumnResizeStart,\n lastResizableColumnKey,\n resettableColumnKeys,\n renderDataColumns,\n resizeColumnsEnabled,\n resolvedRenderColumns,\n resizedColumns,\n };\n};\n\nexport default useResolvedRenderColumns;\n"],"names":["useResolvedRenderColumns","props","columnOrder","onColumnOrderChange","onColumnResize","renderHeaderColumns","viewType","renderDataColumns","useMemo","column","baseRenderColumnDefinitions","draggableColumnsEnabled","draggableColumnKeys","handleColumnDragEnd","orderedColumns","useDraggableColumns","resizeColumnsEnabled","handleColumnResizeReset","handleColumnResizeStart","lastResizableColumnKey","resettableColumnKeys","resizedColumns","useResizableColumns","resolvedRenderColumns","renderColumnsByKey","renderColumn","columnDefinitionsByKey","columnIndexByKey","index"],"mappings":";;;AA8CA,MAAMA,IAA2B,CAC7BC,MAC0C;AAC1C,QAAM,EAAE,aAAAC,GAAa,qBAAAC,GAAqB,gBAAAC,GAAgB,qBAAAC,GAAqB,UAAAC,MAAaL,GAKtFM,IAAoBC;AAAA,IACtB,MACIH,EAAoB;AAAA,MAAQ,CAAAI,MACxBA,EAAO,aAAaA,EAAO,YAAY,IACjC;AAAA,QACI;AAAA,UACI,GAAGA;AAAA,UACH,WAAWA,EAAO;AAAA,QAAA;AAAA,MACtB,IAEJ,CAAA;AAAA,IAAC;AAAA,IAEf,CAACJ,CAAmB;AAAA,EAAA,GAGlBK,IAA8BF;AAAA,IAChC,MACID,EAAkB,IAAI,CAAAE,OAAW;AAAA,MAC7B,KAAKA,EAAO;AAAA,MACZ,OAAOA,EAAO;AAAA,MACd,aAAaA,EAAO;AAAA,MACpB,OAAOA,EAAO;AAAA,MACd,gBAAgBA,EAAO;AAAA,MACvB,gBAAgBA,EAAO;AAAA,MACvB,WAAWA,EAAO;AAAA,MAClB,YAAYA,EAAO;AAAA,MACnB,iBAAiBA,EAAO;AAAA,MACxB,iBAAiBA,EAAO;AAAA,MACxB,cAAcA,EAAO;AAAA,MACrB,UAAUA,EAAO;AAAA,IAAA,E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d,MAAU;AAAA,QAChCA,EAAO;AAAA,QACP;AAAA,UACI,KAAKA,EAAO;AAAA,UACZ,OAAOA,EAAO;AAAA,UACd,aAAaA,EAAO;AAAA,UACpB,MAAMA,EAAO;AAAA,UACb,QAAQA,EAAO;AAAA,UACf,WAAWA,EAAO;AAAA,UAClB,OAAOA,EAAO;AAAA,UACd,gBAAgBA,EAAO;AAAA,UACvB,gBAAgBA,EAAO;AAAA,UACvB,WAAWA,EAAO;AAAA,UAClB,YAAYA,EAAO;AAAA,UACnB,iBAAiBA,EAAO;AAAA,UACxB,WAAW;AAAA,UACX,iBAAiBA,EAAO;AAAA,UACxB,cAAcA,EAAO;AAAA,UACrB,UAAUA,EAAO;AAAA,QAAA;AAAA,MACrB,CACH;AAAA,IAAA;AAAA,IAET,CAACc,CAAqB;AAAA,EAAA,GAEpBI,IAAmBnB;AAAA,IACrB,MAAM,IAAI,IAAIe,EAAsB,IAAI,CAACd,GAAQmB,MAAU,CAACnB,EAAO,WAAWmB,CAAK,CAAU,CAAC;AAAA,IAC9F,CAACL,CAAqB;AAAA,EAAA;AAG1B,SAAO;AAAA,IACH,wBAAAG;AAAA,IACA,kBAAAC;AAAA,IACA,qBAAAf;AAAA,IACA,yBAAAD;AAAA,IACA,qBAAAE;AAAA,IACA,yBAAAI;AAAA,IACA,yBAAAC;AAAA,IACA,wBAAAC;AAAA,IACA,sBAAAC;AAAA,IACA,mBAAAb;AAAA,IACA,sBAAAS;AAAA,IACA,uBAAAO;AAAA,IACA,gBAAAF;AAAA,EAAA;AAER;"}
|
|
@@ -9,7 +9,7 @@ type UseResolvedRenderHeaderProps<RowType extends TableRowData> = {
|
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
11
|
* Builds the normalized header layout from registered header cells and the
|
|
12
|
-
* already-resolved
|
|
12
|
+
* already-resolved data columns.
|
|
13
13
|
*
|
|
14
14
|
* `useResolvedRenderColumns(...)` decides which columns actually exist after
|
|
15
15
|
* reorder/resize behavior. This hook takes that flat column model plus the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useResolvedRenderHeader.js","sources":["../../../../src/components/table/runtime/useResolvedRenderHeader.ts"],"sourcesContent":["import { useMemo } from 'react';\n\nimport type { RenderHeaderColumn } from '../context/TableRenderContext';\nimport type { TableViewHeader } from '../model/tableView.types';\nimport type { TableColumnDefinition, TableRowData, TableSortDirection } from '../Table.types';\n\ntype UseResolvedRenderHeaderProps<RowType extends TableRowData> = {\n renderHeaderColumns: RenderHeaderColumn<RowType>[];\n resolvedRenderColumns: RenderHeaderColumn<RowType>[];\n sortBy?: string | string[];\n sortDirection?: TableSortDirection;\n};\n\n/**\n * Builds the normalized header layout from registered header cells and the\n * already-resolved
|
|
1
|
+
{"version":3,"file":"useResolvedRenderHeader.js","sources":["../../../../src/components/table/runtime/useResolvedRenderHeader.ts"],"sourcesContent":["import { useMemo } from 'react';\n\nimport type { RenderHeaderColumn } from '../context/TableRenderContext';\nimport type { TableViewHeader } from '../model/tableView.types';\nimport type { TableColumnDefinition, TableRowData, TableSortDirection } from '../Table.types';\n\ntype UseResolvedRenderHeaderProps<RowType extends TableRowData> = {\n renderHeaderColumns: RenderHeaderColumn<RowType>[];\n resolvedRenderColumns: RenderHeaderColumn<RowType>[];\n sortBy?: string | string[];\n sortDirection?: TableSortDirection;\n};\n\n/**\n * Builds the normalized header layout from registered header cells and the\n * already-resolved data columns.\n *\n * `useResolvedRenderColumns(...)` decides which columns actually exist after\n * reorder/resize behavior. This hook takes that flat column model plus the\n * registered header cells and computes the final header grid:\n * - row count\n * - column start positions\n * - row/column spans\n * - sortable state for the active sort key\n * - `source` metadata for downstream header/cell consumers\n *\n * The result is a stable header view model that `TableHeader` can render\n * without repeating placement logic.\n */\nconst useResolvedRenderHeader = <RowType extends TableRowData>(\n props: UseResolvedRenderHeaderProps<RowType>\n): TableViewHeader<RowType> | undefined => {\n const { renderHeaderColumns, resolvedRenderColumns, sortBy, sortDirection } = props;\n\n return useMemo<TableViewHeader<RowType> | undefined>(() => {\n if (renderHeaderColumns.length === 0 || resolvedRenderColumns.length === 0) {\n return;\n }\n\n const sortedColumnKeys = new Set(Array.isArray(sortBy) ? sortBy : sortBy ? [sortBy] : []);\n const rowCount = Math.max(...renderHeaderColumns.map(column => column.row + column.rowSpan - 1), 1);\n const occupied = Array.from({ length: rowCount }, () => Array(resolvedRenderColumns.length).fill(false));\n const resolvedRenderColumnsByKey = new Map(\n resolvedRenderColumns.map(column => [column.columnKey, column] as const)\n );\n const columnStartByKey = new Map(\n resolvedRenderColumns.map((column, index) => [column.columnKey, index + 1] as const)\n );\n\n // Group headers without a direct `columnKey` still need a column start.\n // Find the next free slot by walking the occupied grid from left to right.\n const findColumnStart = (rowStart: number, colSpan: number) => {\n for (let candidate = 1; candidate <= resolvedRenderColumns.length - colSpan + 1; candidate += 1) {\n const hasFreeSlot = occupied[rowStart - 1]\n ?.slice(candidate - 1, candidate - 1 + colSpan)\n .every(isUsed => !isUsed);\n\n if (hasFreeSlot) {\n return candidate;\n }\n }\n\n return 1;\n };\n\n const columns = renderHeaderColumns.map(column => {\n const resolvedRenderColumn = column.columnKey\n ? resolvedRenderColumnsByKey.get(column.columnKey)\n : undefined;\n const sourceColumnDefinition: TableColumnDefinition<RowType> | undefined = resolvedRenderColumn?.columnKey\n ? {\n key: resolvedRenderColumn.columnKey,\n label: resolvedRenderColumn.label,\n width: resolvedRenderColumn.width,\n mobileLabel: resolvedRenderColumn.mobileLabel,\n horizontalAlign: resolvedRenderColumn.horizontalAlign,\n headerClassName: resolvedRenderColumn.headerClassName,\n hideOnMobile: resolvedRenderColumn.hideOnMobile,\n sortable: resolvedRenderColumn.sortable,\n draggable: resolvedRenderColumn.draggable,\n resizeable: resolvedRenderColumn.resizeable,\n minResizeWidth: resolvedRenderColumn.minResizeWidth,\n maxResizeWidth: resolvedRenderColumn.maxResizeWidth,\n }\n : undefined;\n const columnStart = resolvedRenderColumn\n ? (columnStartByKey.get(resolvedRenderColumn.columnKey) ?? 1)\n : findColumnStart(column.row, column.colSpan);\n\n // Mark the occupied grid so following grouped header cells can find\n // the next free placement slot in multi-row header layouts.\n for (let rowIndex = column.row - 1; rowIndex < column.row - 1 + column.rowSpan; rowIndex += 1) {\n for (\n let columnIndex = columnStart - 1;\n columnIndex < columnStart - 1 + column.colSpan;\n columnIndex += 1\n ) {\n if (occupied[rowIndex]?.[columnIndex] !== undefined) {\n occupied[rowIndex][columnIndex] = true;\n }\n }\n }\n\n return {\n key: column.id,\n columnKey: column.columnKey,\n label: column.label,\n icon: column.icon,\n filter: column.filter,\n hideLabel: column.hideLabel,\n horizontalAlign: resolvedRenderColumn?.horizontalAlign ?? column.horizontalAlign,\n verticalAlign: resolvedRenderColumn?.verticalAlign ?? column.verticalAlign,\n className: undefined,\n headerClassName: resolvedRenderColumn?.headerClassName ?? column.headerClassName,\n hideOnMobile: resolvedRenderColumn?.hideOnMobile ?? column.hideOnMobile,\n draggable: resolvedRenderColumn?.draggable ?? column.draggable,\n resizeable: resolvedRenderColumn?.resizeable ?? column.resizeable,\n sortable: resolvedRenderColumn?.sortable ?? column.sortable,\n sortDirection: column.columnKey && sortedColumnKeys.has(column.columnKey) ? sortDirection : undefined,\n rowStart: column.row,\n rowSpan: column.rowSpan,\n columnStart,\n colSpan: column.colSpan,\n source: sourceColumnDefinition,\n };\n });\n\n return {\n rowCount,\n totalColumnCount: resolvedRenderColumns.length,\n columns,\n };\n }, [renderHeaderColumns, resolvedRenderColumns, sortBy, sortDirection]);\n};\n\nexport default useResolvedRenderHeader;\n"],"names":["useResolvedRenderHeader","props","renderHeaderColumns","resolvedRenderColumns","sortBy","sortDirection","useMemo","sortedColumnKeys","rowCount","column","occupied","resolvedRenderColumnsByKey","columnStartByKey","index","findColumnStart","rowStart","colSpan","candidate","isUsed","columns","resolvedRenderColumn","sourceColumnDefinition","columnStart","rowIndex","columnIndex"],"mappings":";AA6BA,MAAMA,IAA0B,CAC5BC,MACuC;AACvC,QAAM,EAAE,qBAAAC,GAAqB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A,MACA,kBAAkBL,EAAsB;AAAA,MACxC,SAAAgB;AAAA,IAAA;AAAA,EAER,GAAG,CAACjB,GAAqBC,GAAuBC,GAAQC,CAAa,CAAC;AAC1E;"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { MutableRefObject, PointerEvent as ReactPointerEvent } from 'react';
|
|
1
|
+
import { MutableRefObject, PointerEvent as ReactPointerEvent, ReactNode, RefObject } from 'react';
|
|
2
2
|
export type DraggablePosition = {
|
|
3
3
|
/**
|
|
4
|
-
* Top offset in pixels relative to the
|
|
4
|
+
* Top offset in pixels relative to the active positioning context.
|
|
5
5
|
*/
|
|
6
6
|
top: number;
|
|
7
7
|
/**
|
|
8
|
-
* Left offset in pixels relative to the
|
|
8
|
+
* Left offset in pixels relative to the active positioning context.
|
|
9
9
|
*/
|
|
10
10
|
left: number;
|
|
11
11
|
/**
|
|
@@ -29,7 +29,29 @@ export type UseDraggableResult<T extends HTMLElement> = {
|
|
|
29
29
|
/**
|
|
30
30
|
* Pointer down handler for the dedicated drag handle element.
|
|
31
31
|
*/
|
|
32
|
-
|
|
32
|
+
onDragHandleDown: (event: ReactPointerEvent<HTMLElement>) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Renders the provided element through the shared portal root in viewport mode.
|
|
35
|
+
* An optional custom target can be passed for specialized overlay hosts.
|
|
36
|
+
* In container mode, the element is returned unchanged and this helper is usually not needed.
|
|
37
|
+
*/
|
|
38
|
+
renderElement: (element: ReactNode, target?: HTMLElement | null) => ReactNode;
|
|
39
|
+
};
|
|
40
|
+
export type UseDraggableElementOptions = {
|
|
41
|
+
/**
|
|
42
|
+
* Defines whether drag coordinates are resolved against the viewport or a collision container.
|
|
43
|
+
* Viewport mode also enables portal rendering via `renderElement`.
|
|
44
|
+
*/
|
|
45
|
+
positioning?: 'viewport' | 'container';
|
|
46
|
+
/**
|
|
47
|
+
* Optional initial position for the draggable element.
|
|
48
|
+
* Use `center` to center the element inside the active positioning context on mount.
|
|
49
|
+
*/
|
|
50
|
+
initialPosition?: 'center' | Pick<DraggablePosition, 'top' | 'left'>;
|
|
51
|
+
/**
|
|
52
|
+
* Optional container whose visible client rect is used as the drag boundary in container mode.
|
|
53
|
+
*/
|
|
54
|
+
collisionContainerRef?: RefObject<HTMLElement | null>;
|
|
33
55
|
};
|
|
34
|
-
declare const useDraggableElement: <T extends HTMLElement = HTMLDivElement>() => UseDraggableResult<T>;
|
|
56
|
+
declare const useDraggableElement: <T extends HTMLElement = HTMLDivElement>(options?: UseDraggableElementOptions) => UseDraggableResult<T>;
|
|
35
57
|
export default useDraggableElement;
|
|
@@ -1,49 +1,126 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { useState as M, useRef as C, useEffect as Y, useCallback as H, useLayoutEffect as N } from "react";
|
|
2
|
+
import { createPortal as O } from "react-dom";
|
|
3
|
+
import { getOrCreatePortalRoot as W } from "../utils/portalRoot.js";
|
|
4
|
+
const y = 4, v = "is-dragging", s = (a, e, o) => Math.min(o, Math.max(e, a)), R = (a) => a?.current?.getBoundingClientRect() ?? null, I = (a, e, o) => a === "container" && o ? {
|
|
5
|
+
top: s(
|
|
6
|
+
(o.height - e.height) / 2,
|
|
7
|
+
0,
|
|
8
|
+
Math.max(0, o.height - e.height)
|
|
9
|
+
),
|
|
10
|
+
left: s(
|
|
11
|
+
(o.width - e.width) / 2,
|
|
12
|
+
0,
|
|
13
|
+
Math.max(0, o.width - e.width)
|
|
14
|
+
)
|
|
15
|
+
} : {
|
|
16
|
+
top: s(
|
|
17
|
+
(window.innerHeight - e.height) / 2,
|
|
18
|
+
0,
|
|
19
|
+
Math.max(0, window.innerHeight - e.height)
|
|
20
|
+
),
|
|
21
|
+
left: s(
|
|
22
|
+
(window.innerWidth - e.width) / 2,
|
|
23
|
+
0,
|
|
24
|
+
Math.max(0, window.innerWidth - e.width)
|
|
25
|
+
)
|
|
26
|
+
}, j = (a = {}) => {
|
|
27
|
+
const { positioning: e = "viewport", initialPosition: o, collisionContainerRef: d } = a, [u, D] = M(!1), [g, p] = M({ top: 0, left: 0, hasDragged: !1 }), [x, L] = M(null), h = C(null), w = C(null), c = e === "viewport";
|
|
28
|
+
Y(() => {
|
|
29
|
+
if (!c) {
|
|
30
|
+
L(null);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
L(W());
|
|
34
|
+
}, [c]);
|
|
35
|
+
const S = H(
|
|
36
|
+
(t, r) => {
|
|
37
|
+
if (!c)
|
|
38
|
+
return t;
|
|
39
|
+
const n = r ?? x;
|
|
40
|
+
return n ? O(t, n) : null;
|
|
41
|
+
},
|
|
42
|
+
[c, x]
|
|
43
|
+
);
|
|
44
|
+
N(() => {
|
|
45
|
+
if (g.hasDragged || !o)
|
|
46
|
+
return;
|
|
47
|
+
const t = h.current;
|
|
48
|
+
if (!t)
|
|
49
|
+
return;
|
|
50
|
+
const r = o === "center" ? I(
|
|
51
|
+
e,
|
|
52
|
+
t.getBoundingClientRect(),
|
|
53
|
+
R(d)
|
|
54
|
+
) : o;
|
|
55
|
+
p(
|
|
56
|
+
(n) => n.top === r.top && n.left === r.left ? n : { top: r.top, left: r.left, hasDragged: !1 }
|
|
57
|
+
);
|
|
58
|
+
}, [d, o, g.hasDragged, e]);
|
|
59
|
+
const T = H((t) => {
|
|
4
60
|
if (t.button !== 0)
|
|
5
61
|
return;
|
|
6
62
|
t.preventDefault(), t.stopPropagation();
|
|
7
|
-
const r =
|
|
63
|
+
const r = h.current;
|
|
8
64
|
if (!r)
|
|
9
65
|
return;
|
|
10
66
|
const n = r.getBoundingClientRect();
|
|
11
|
-
|
|
67
|
+
w.current = {
|
|
12
68
|
offsetX: t.clientX - n.left,
|
|
13
69
|
offsetY: t.clientY - n.top,
|
|
14
70
|
startX: t.clientX,
|
|
15
71
|
startY: t.clientY,
|
|
16
72
|
hasMoved: !1
|
|
17
|
-
},
|
|
73
|
+
}, D(!0);
|
|
18
74
|
}, []);
|
|
19
|
-
return
|
|
20
|
-
if (!
|
|
75
|
+
return Y(() => {
|
|
76
|
+
if (!u)
|
|
21
77
|
return;
|
|
22
78
|
const t = document.documentElement;
|
|
23
|
-
t.classList.add(
|
|
24
|
-
const r = (
|
|
25
|
-
const
|
|
26
|
-
if (!
|
|
79
|
+
t.classList.add(v);
|
|
80
|
+
const r = (B) => {
|
|
81
|
+
const i = w.current, P = h.current;
|
|
82
|
+
if (!i || !P)
|
|
83
|
+
return;
|
|
84
|
+
const { clientX: m, clientY: E } = B, _ = Math.hypot(m - i.startX, E - i.startY);
|
|
85
|
+
if (!i.hasMoved && _ < y)
|
|
27
86
|
return;
|
|
28
|
-
|
|
29
|
-
|
|
87
|
+
i.hasMoved || (i.hasMoved = !0);
|
|
88
|
+
const f = P.getBoundingClientRect(), l = R(d);
|
|
89
|
+
if (e === "container" && l) {
|
|
90
|
+
const A = s(
|
|
91
|
+
m - l.left - i.offsetX,
|
|
92
|
+
0,
|
|
93
|
+
Math.max(0, l.width - f.width)
|
|
94
|
+
), G = s(
|
|
95
|
+
E - l.top - i.offsetY,
|
|
96
|
+
0,
|
|
97
|
+
Math.max(0, l.height - f.height)
|
|
98
|
+
);
|
|
99
|
+
p({
|
|
100
|
+
top: G,
|
|
101
|
+
left: A,
|
|
102
|
+
hasDragged: !0
|
|
103
|
+
});
|
|
30
104
|
return;
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
top:
|
|
35
|
-
|
|
105
|
+
}
|
|
106
|
+
const X = {
|
|
107
|
+
left: s(m - i.offsetX, 0, Math.max(0, window.innerWidth - f.width)),
|
|
108
|
+
top: s(E - i.offsetY, 0, Math.max(0, window.innerHeight - f.height))
|
|
109
|
+
};
|
|
110
|
+
p({
|
|
111
|
+
top: X.top,
|
|
112
|
+
left: X.left,
|
|
36
113
|
hasDragged: !0
|
|
37
114
|
});
|
|
38
115
|
}, n = () => {
|
|
39
|
-
t.classList.remove(
|
|
116
|
+
t.classList.remove(v), D(!1), w.current = null;
|
|
40
117
|
};
|
|
41
118
|
return window.addEventListener("pointermove", r), window.addEventListener("pointerup", n), window.addEventListener("pointercancel", n), () => {
|
|
42
|
-
window.removeEventListener("pointermove", r), window.removeEventListener("pointerup", n), window.removeEventListener("pointercancel", n), t.classList.remove(
|
|
119
|
+
window.removeEventListener("pointermove", r), window.removeEventListener("pointerup", n), window.removeEventListener("pointercancel", n), t.classList.remove(v);
|
|
43
120
|
};
|
|
44
|
-
}, [
|
|
121
|
+
}, [d, u, e]), { draggableRef: h, isDragging: u, position: g, onDragHandleDown: T, renderElement: S };
|
|
45
122
|
};
|
|
46
123
|
export {
|
|
47
|
-
|
|
124
|
+
j as default
|
|
48
125
|
};
|
|
49
126
|
//# sourceMappingURL=useDraggableElement.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDraggableElement.js","sources":["../../src/hooks/useDraggableElement.ts"],"sourcesContent":["import {\n useCallback,\n useEffect,\n useRef,\n useState,\n type MutableRefObject,\n type PointerEvent as ReactPointerEvent,\n} from 'react';\n\nexport type DraggablePosition = {\n /**\n * Top offset in pixels relative to the viewport.\n */\n top: number;\n\n /**\n * Left offset in pixels relative to the viewport.\n */\n left: number;\n\n /**\n * Indicates whether the element has been moved by dragging at least once.\n */\n hasDragged: boolean;\n};\n\nexport type UseDraggableResult<T extends HTMLElement> = {\n /**\n * Ref that must be attached to the draggable element container.\n */\n draggableRef: MutableRefObject<T | null>;\n\n /**\n * Indicates whether a drag interaction is currently active.\n */\n isDragging: boolean;\n\n /**\n * Current draggable coordinates and drag-state metadata.\n */\n position: DraggablePosition;\n\n /**\n * Pointer down handler for the dedicated drag handle element.\n */\n onDragHandlePointerDown: (event: ReactPointerEvent<HTMLElement>) => void;\n};\n\ntype DraggableState = {\n offsetX: number;\n offsetY: number;\n startX: number;\n startY: number;\n hasMoved: boolean;\n};\n\nconst MOVEMENT_THRESHOLD_PX = 4;\nconst DRAGGING_CLASS_NAME = 'is-dragging';\n\nconst clampToRange = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value));\n\nconst useDraggableElement = <T extends HTMLElement = HTMLDivElement>(): UseDraggableResult<T> => {\n const [isDragging, setIsDragging] = useState(false);\n const [position, setPosition] = useState<DraggablePosition>({ top: 0, left: 0, hasDragged: false });\n\n const draggableRef = useRef<T | null>(null);\n const dragStateRef = useRef<DraggableState | null>(null);\n\n const onDragHandlePointerDown = useCallback((event: ReactPointerEvent<HTMLElement>) => {\n if (event.button !== 0) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n const draggableElement = draggableRef.current;\n if (!draggableElement) {\n return;\n }\n\n const rect = draggableElement.getBoundingClientRect();\n dragStateRef.current = {\n offsetX: event.clientX - rect.left,\n offsetY: event.clientY - rect.top,\n startX: event.clientX,\n startY: event.clientY,\n hasMoved: false,\n };\n setIsDragging(true);\n }, []);\n\n useEffect(() => {\n if (!isDragging) {\n return;\n }\n\n const rootElement = document.documentElement;\n rootElement.classList.add(DRAGGING_CLASS_NAME);\n\n const handlePointerMove = (event: PointerEvent) => {\n const dragState = dragStateRef.current;\n const draggableElement = draggableRef.current;\n if (!dragState || !draggableElement) {\n return;\n }\n\n const movedDistance = Math.hypot(event.clientX - dragState.startX, event.clientY - dragState.startY);\n if (!dragState.hasMoved && movedDistance < MOVEMENT_THRESHOLD_PX) {\n return;\n }\n\n if (!dragState.hasMoved) {\n dragState.hasMoved = true;\n }\n\n const rect = draggableElement.getBoundingClientRect();\n const maxLeft = Math.max(0, window.innerWidth - rect.width);\n const maxTop = Math.max(0, window.innerHeight - rect.height);\n const nextLeft = clampToRange(event.clientX - dragState.offsetX, 0, maxLeft);\n const nextTop = clampToRange(event.clientY - dragState.offsetY, 0, maxTop);\n\n setPosition({\n top: nextTop,\n left: nextLeft,\n hasDragged: true,\n });\n };\n\n const handlePointerRelease = () => {\n rootElement.classList.remove(DRAGGING_CLASS_NAME);\n setIsDragging(false);\n dragStateRef.current = null;\n };\n\n window.addEventListener('pointermove', handlePointerMove);\n window.addEventListener('pointerup', handlePointerRelease);\n window.addEventListener('pointercancel', handlePointerRelease);\n\n return () => {\n window.removeEventListener('pointermove', handlePointerMove);\n window.removeEventListener('pointerup', handlePointerRelease);\n window.removeEventListener('pointercancel', handlePointerRelease);\n rootElement.classList.remove(DRAGGING_CLASS_NAME);\n };\n }, [isDragging]);\n\n return { draggableRef, isDragging, position, onDragHandlePointerDown };\n};\n\nexport default useDraggableElement;\n"],"names":["MOVEMENT_THRESHOLD_PX","DRAGGING_CLASS_NAME","clampToRange","value","min","max","useDraggableElement","isDragging","setIsDragging","useState","position","setPosition","draggableRef","useRef","dragStateRef","onDragHandlePointerDown","useCallback","event","draggableElement","rect","useEffect","rootElement","handlePointerMove","dragState","movedDistance","maxLeft","maxTop","nextLeft","nextTop","handlePointerRelease"],"mappings":";AAwDA,MAAMA,IAAwB,GACxBC,IAAsB,eAEtBC,IAAe,CAACC,GAAeC,GAAaC,MAAgB,KAAK,IAAIA,GAAK,KAAK,IAAID,GAAKD,CAAK,CAAC,GAE9FG,IAAsB,MAAqE;AAC7F,QAAM,CAACC,GAAYC,CAAa,IAAIC,EAAS,EAAK,GAC5C,CAACC,GAAUC,CAAW,IAAIF,EAA4B,EAAE,KAAK,GAAG,MAAM,GAAG,YAAY,GAAA,CAAO,GAE5FG,IAAeC,EAAiB,IAAI,GACpCC,IAAeD,EAA8B,IAAI,GAEjDE,IAA0BC,EAAY,CAACC,MAA0C;AACnF,QAAIA,EAAM,WAAW;AACjB;AAGJ,IAAAA,EAAM,eAAA,GACNA,EAAM,gBAAA;AAEN,UAAMC,IAAmBN,EAAa;AACtC,QAAI,CAACM;AACD;AAGJ,UAAMC,IAAOD,EAAiB,sBAAA;AAC9B,IAAAJ,EAAa,UAAU;AAAA,MACnB,SAASG,EAAM,UAAUE,EAAK;AAAA,MAC9B,SAASF,EAAM,UAAUE,EAAK;AAAA,MAC9B,QAAQF,EAAM;AAAA,MACd,QAAQA,EAAM;AAAA,MACd,UAAU;AAAA,IAAA,GAEdT,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G,CAACM,CAAU,CAAC,GAER,EAAE,cAAAK,GAAc,YAAAL,GAAY,UAAAG,GAAU,yBAAAK,EAAA;AACjD;"}
|
|
1
|
+
{"version":3,"file":"useDraggableElement.js","sources":["../../src/hooks/useDraggableElement.ts"],"sourcesContent":["import {\n useCallback,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n type MutableRefObject,\n type PointerEvent as ReactPointerEvent,\n type ReactNode,\n type RefObject,\n} from 'react';\nimport { createPortal } from 'react-dom';\n\nimport { getOrCreatePortalRoot } from '../utils/portalRoot';\n\nexport type DraggablePosition = {\n /**\n * Top offset in pixels relative to the active positioning context.\n */\n top: number;\n\n /**\n * Left offset in pixels relative to the active positioning context.\n */\n left: number;\n\n /**\n * Indicates whether the element has been moved by dragging at least once.\n */\n hasDragged: boolean;\n};\n\nexport type UseDraggableResult<T extends HTMLElement> = {\n /**\n * Ref that must be attached to the draggable element container.\n */\n draggableRef: MutableRefObject<T | null>;\n\n /**\n * Indicates whether a drag interaction is currently active.\n */\n isDragging: boolean;\n\n /**\n * Current draggable coordinates and drag-state metadata.\n */\n position: DraggablePosition;\n\n /**\n * Pointer down handler for the dedicated drag handle element.\n */\n onDragHandleDown: (event: ReactPointerEvent<HTMLElement>) => void;\n\n /**\n * Renders the provided element through the shared portal root in viewport mode.\n * An optional custom target can be passed for specialized overlay hosts.\n * In container mode, the element is returned unchanged and this helper is usually not needed.\n */\n renderElement: (element: ReactNode, target?: HTMLElement | null) => ReactNode;\n};\n\nexport type UseDraggableElementOptions = {\n /**\n * Defines whether drag coordinates are resolved against the viewport or a collision container.\n * Viewport mode also enables portal rendering via `renderElement`.\n */\n positioning?: 'viewport' | 'container';\n\n /**\n * Optional initial position for the draggable element.\n * Use `center` to center the element inside the active positioning context on mount.\n */\n initialPosition?: 'center' | Pick<DraggablePosition, 'top' | 'left'>;\n\n /**\n * Optional container whose visible client rect is used as the drag boundary in container mode.\n */\n collisionContainerRef?: RefObject<HTMLElement | null>;\n};\n\ntype DraggableState = {\n offsetX: number;\n offsetY: number;\n startX: number;\n startY: number;\n hasMoved: boolean;\n};\n\nconst MOVEMENT_THRESHOLD_PX = 4;\nconst DRAGGING_CLASS_NAME = 'is-dragging';\n\nconst clampToRange = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value));\n\nconst resolveCollisionContainerRect = (collisionContainerRef?: RefObject<HTMLElement | null>) =>\n collisionContainerRef?.current?.getBoundingClientRect() ?? null;\n\nconst resolveCenteredPosition = (\n positioning: UseDraggableElementOptions['positioning'],\n draggableRect: DOMRect,\n collisionContainerRect: DOMRect | null\n) => {\n if (positioning === 'container' && collisionContainerRect) {\n return {\n top: clampToRange(\n (collisionContainerRect.height - draggableRect.height) / 2,\n 0,\n Math.max(0, collisionContainerRect.height - draggableRect.height)\n ),\n left: clampToRange(\n (collisionContainerRect.width - draggableRect.width) / 2,\n 0,\n Math.max(0, collisionContainerRect.width - draggableRect.width)\n ),\n };\n }\n\n return {\n top: clampToRange(\n (window.innerHeight - draggableRect.height) / 2,\n 0,\n Math.max(0, window.innerHeight - draggableRect.height)\n ),\n left: clampToRange(\n (window.innerWidth - draggableRect.width) / 2,\n 0,\n Math.max(0, window.innerWidth - draggableRect.width)\n ),\n };\n};\n\nconst useDraggableElement = <T extends HTMLElement = HTMLDivElement>(\n options: UseDraggableElementOptions = {}\n): UseDraggableResult<T> => {\n const { positioning = 'viewport', initialPosition, collisionContainerRef } = options;\n\n const [isDragging, setIsDragging] = useState(false);\n const [position, setPosition] = useState<DraggablePosition>({ top: 0, left: 0, hasDragged: false });\n const [portalRoot, setPortalRoot] = useState<HTMLElement | null>(null);\n\n const draggableRef = useRef<T | null>(null);\n const dragStateRef = useRef<DraggableState | null>(null);\n const portalEnabled = positioning === 'viewport';\n\n useEffect(() => {\n if (!portalEnabled) {\n setPortalRoot(null);\n return;\n }\n\n setPortalRoot(getOrCreatePortalRoot());\n }, [portalEnabled]);\n\n const renderElement = useCallback(\n (element: ReactNode, target?: HTMLElement | null) => {\n if (!portalEnabled) {\n return element;\n }\n\n const renderTarget = target ?? portalRoot;\n return renderTarget ? createPortal(element, renderTarget) : null;\n },\n [portalEnabled, portalRoot]\n );\n\n useLayoutEffect(() => {\n if (position.hasDragged || !initialPosition) {\n return;\n }\n\n const draggableElement = draggableRef.current;\n if (!draggableElement) {\n return;\n }\n\n const nextPosition =\n initialPosition === 'center'\n ? resolveCenteredPosition(\n positioning,\n draggableElement.getBoundingClientRect(),\n resolveCollisionContainerRect(collisionContainerRef)\n )\n : initialPosition;\n\n setPosition(currentPosition =>\n currentPosition.top === nextPosition.top && currentPosition.left === nextPosition.left\n ? currentPosition\n : { top: nextPosition.top, left: nextPosition.left, hasDragged: false }\n );\n }, [collisionContainerRef, initialPosition, position.hasDragged, positioning]);\n\n const onDragHandleDown = useCallback((event: ReactPointerEvent<HTMLElement>) => {\n if (event.button !== 0) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n const draggableElement = draggableRef.current;\n if (!draggableElement) {\n return;\n }\n\n const rect = draggableElement.getBoundingClientRect();\n dragStateRef.current = {\n offsetX: event.clientX - rect.left,\n offsetY: event.clientY - rect.top,\n startX: event.clientX,\n startY: event.clientY,\n hasMoved: false,\n };\n setIsDragging(true);\n }, []);\n\n useEffect(() => {\n if (!isDragging) {\n return;\n }\n\n const rootElement = document.documentElement;\n rootElement.classList.add(DRAGGING_CLASS_NAME);\n\n const handlePointerMove = (event: PointerEvent) => {\n const dragState = dragStateRef.current;\n const draggableElement = draggableRef.current;\n if (!dragState || !draggableElement) {\n return;\n }\n\n const { clientX, clientY } = event;\n\n const movedDistance = Math.hypot(clientX - dragState.startX, clientY - dragState.startY);\n if (!dragState.hasMoved && movedDistance < MOVEMENT_THRESHOLD_PX) {\n return;\n }\n\n if (!dragState.hasMoved) {\n dragState.hasMoved = true;\n }\n\n const rect = draggableElement.getBoundingClientRect();\n const collisionContainerRect = resolveCollisionContainerRect(collisionContainerRef);\n\n if (positioning === 'container' && collisionContainerRect) {\n const nextLeftPos = clampToRange(\n clientX - collisionContainerRect.left - dragState.offsetX,\n 0,\n Math.max(0, collisionContainerRect.width - rect.width)\n );\n\n const nextTopPos = clampToRange(\n clientY - collisionContainerRect.top - dragState.offsetY,\n 0,\n Math.max(0, collisionContainerRect.height - rect.height)\n );\n\n setPosition({\n top: nextTopPos,\n left: nextLeftPos,\n hasDragged: true,\n });\n\n return;\n }\n\n const nextPosition = {\n left: clampToRange(clientX - dragState.offsetX, 0, Math.max(0, window.innerWidth - rect.width)),\n top: clampToRange(clientY - dragState.offsetY, 0, Math.max(0, window.innerHeight - rect.height)),\n };\n\n setPosition({\n top: nextPosition.top,\n left: nextPosition.left,\n hasDragged: true,\n });\n };\n\n const handlePointerRelease = () => {\n rootElement.classList.remove(DRAGGING_CLASS_NAME);\n setIsDragging(false);\n dragStateRef.current = null;\n };\n\n window.addEventListener('pointermove', handlePointerMove);\n window.addEventListener('pointerup', handlePointerRelease);\n window.addEventListener('pointercancel', handlePointerRelease);\n\n return () => {\n window.removeEventListener('pointermove', handlePointerMove);\n window.removeEventListener('pointerup', handlePointerRelease);\n window.removeEventListener('pointercancel', handlePointerRelease);\n rootElement.classList.remove(DRAGGING_CLASS_NAME);\n };\n }, [collisionContainerRef, isDragging, positioning]);\n\n return { draggableRef, isDragging, position, onDragHandleDown, renderElement };\n};\n\nexport default useDraggableElement;\n"],"names":["MOVEMENT_THRESHOLD_PX","DRAGGING_CLASS_NAME","clampToRange","value","min","max","resolveCollisionContainerRect","collisionContainerRef","resolveCenteredPosition","positioning","draggableRect","collisionContainerRect","useDraggableElement","options","initialPosition","isDragging","setIsDragging","useState","position","setPosition","portalRoot","setPortalRoot","draggableRef","useRef","dragStateRef","portalEnabled","useEffect","getOrCreatePortalRoot","renderElement","useCallback","element","target","renderTarget","createPortal","useLayoutEffect","draggableElement","nextPosition","currentPosition","onDragHandleDown","event","rect","rootElement","handlePointerMove","dragState","clientX","clientY","movedDistance","nextLeftPos","nextTopPos","handlePointerRelease"],"mapp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,KAAKiB,EAAa;AAAA,QAClB,MAAMA,EAAa;AAAA,QACnB,YAAY;AAAA,MAAA,CACf;AAAA,IACL,GAEMa,IAAuB,MAAM;AAC/B,MAAAR,EAAY,UAAU,OAAOxC,CAAmB,GAChDe,EAAc,EAAK,GACnBQ,EAAa,UAAU;AAAA,IAC3B;AAEA,kBAAO,iBAAiB,eAAekB,CAAiB,GACxD,OAAO,iBAAiB,aAAaO,CAAoB,GACzD,OAAO,iBAAiB,iBAAiBA,CAAoB,GAEtD,MAAM;AACT,aAAO,oBAAoB,eAAeP,CAAiB,GAC3D,OAAO,oBAAoB,aAAaO,CAAoB,GAC5D,OAAO,oBAAoB,iBAAiBA,CAAoB,GAChER,EAAY,UAAU,OAAOxC,CAAmB;AAAA,IACpD;AAAA,EACJ,GAAG,CAACM,GAAuBQ,GAAYN,CAAW,CAAC,GAE5C,EAAE,cAAAa,GAAc,YAAAP,GAAY,UAAAG,GAAU,kBAAAoB,GAAkB,eAAAV,EAAA;AACnE;"}
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
import { usePopper as
|
|
3
|
-
const
|
|
4
|
-
const
|
|
1
|
+
import { useRef as d, useState as o, useCallback as i } from "react";
|
|
2
|
+
import { usePopper as b } from "react-popper";
|
|
3
|
+
const R = ({ placement: s = "bottom-start" } = {}) => {
|
|
4
|
+
const p = d(null), [r, n] = o(null), [l, t] = o(!1), e = b(p.current, r, {
|
|
5
5
|
placement: s
|
|
6
|
-
})
|
|
6
|
+
}), u = () => t(!0), c = () => t(!1), a = () => t((m) => !m), f = i(() => {
|
|
7
|
+
e.update?.();
|
|
8
|
+
}, [e.update]);
|
|
7
9
|
return {
|
|
8
10
|
isOpen: l,
|
|
9
|
-
open:
|
|
10
|
-
close:
|
|
11
|
-
toggle:
|
|
12
|
-
|
|
11
|
+
open: u,
|
|
12
|
+
close: c,
|
|
13
|
+
toggle: a,
|
|
14
|
+
update: f,
|
|
15
|
+
referenceRef: p,
|
|
13
16
|
popperElementRef: n,
|
|
14
|
-
popperStyles:
|
|
15
|
-
popperAttributes:
|
|
17
|
+
popperStyles: e.styles.popper,
|
|
18
|
+
popperAttributes: e.attributes.popper
|
|
16
19
|
};
|
|
17
20
|
};
|
|
18
21
|
export {
|
|
19
|
-
|
|
22
|
+
R as default
|
|
20
23
|
};
|
|
21
24
|
//# sourceMappingURL=usePopperDropdown.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePopperDropdown.js","sources":["../../src/hooks/usePopperDropdown.ts"],"sourcesContent":["import { type CSSProperties, useRef, useState } from 'react';\nimport { usePopper } from 'react-popper';\n\ntype UsePopperDropdownResult = {\n isOpen: boolean;\n open: () => void;\n close: () => void;\n toggle: () => void;\n referenceRef: any;\n popperElementRef: (el: HTMLElement | null) => void;\n popperStyles: CSSProperties;\n popperAttributes: Record<string, any>;\n};\n\ntype UsePopperDropdownParams = {\n placement?: 'bottom-start' | 'bottom-end';\n};\n\nconst usePopperDropdown = ({ placement = 'bottom-start' }: UsePopperDropdownParams = {}) => {\n const referenceRef = useRef<HTMLElement>(null);\n const [popperElement, setPopperElement] = useState<HTMLElement | null>(null);\n const [isOpen, setIsOpen] = useState(false);\n\n const popper = usePopper(referenceRef.current, popperElement, {\n placement,\n });\n\n const open = () => setIsOpen(true);\n const close = () => setIsOpen(false);\n const toggle = () => setIsOpen(prev => !prev);\n\n return {\n isOpen,\n open,\n close,\n toggle,\n referenceRef,\n popperElementRef: setPopperElement,\n popperStyles: popper.styles.popper,\n popperAttributes: popper.attributes.popper,\n } as UsePopperDropdownResult;\n};\n\nexport default usePopperDropdown;\n"],"names":["usePopperDropdown","placement","referenceRef","useRef","popperElement","setPopperElement","useState","isOpen","setIsOpen","popper","usePopper","prev"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"usePopperDropdown.js","sources":["../../src/hooks/usePopperDropdown.ts"],"sourcesContent":["import { type CSSProperties, useCallback, useRef, useState } from 'react';\nimport { usePopper } from 'react-popper';\n\ntype UsePopperDropdownResult = {\n isOpen: boolean;\n open: () => void;\n close: () => void;\n toggle: () => void;\n update: () => void;\n referenceRef: any;\n popperElementRef: (el: HTMLElement | null) => void;\n popperStyles: CSSProperties;\n popperAttributes: Record<string, any>;\n};\n\ntype UsePopperDropdownParams = {\n placement?: 'bottom-start' | 'bottom-end';\n};\n\nconst usePopperDropdown = ({ placement = 'bottom-start' }: UsePopperDropdownParams = {}) => {\n const referenceRef = useRef<HTMLElement>(null);\n const [popperElement, setPopperElement] = useState<HTMLElement | null>(null);\n const [isOpen, setIsOpen] = useState(false);\n\n const popper = usePopper(referenceRef.current, popperElement, {\n placement,\n });\n\n const open = () => setIsOpen(true);\n const close = () => setIsOpen(false);\n const toggle = () => setIsOpen(prev => !prev);\n const update = useCallback(() => {\n void popper.update?.();\n }, [popper.update]);\n\n return {\n isOpen,\n open,\n close,\n toggle,\n update,\n referenceRef,\n popperElementRef: setPopperElement,\n popperStyles: popper.styles.popper,\n popperAttributes: popper.attributes.popper,\n } as UsePopperDropdownResult;\n};\n\nexport default usePopperDropdown;\n"],"names":["usePopperDropdown","placement","referenceRef","useRef","popperElement","setPopperElement","useState","isOpen","setIsOpen","popper","usePopper","open","close","toggle","prev","update","useCallback"],"mappings":";;AAmBA,MAAMA,IAAoB,CAAC,EAAE,WAAAC,IAAY,eAAA,IAA4C,CAAA,MAAO;AACxF,QAAMC,IAAeC,EAAoB,IAAI,GACvC,CAACC,GAAeC,CAAgB,IAAIC,EAA6B,IAAI,GACrE,CAACC,GAAQC,CAAS,IAAIF,EAAS,EAAK,GAEpCG,IAASC,EAAUR,EAAa,SAASE,GAAe;AAAA,IAC1D,WAAAH;AAAA,EAAA,CACH,GAEKU,IAAO,MAAMH,EAAU,EAAI,GAC3BI,IAAQ,MAAMJ,EAAU,EAAK,GAC7BK,IAAS,MAAML,EAAU,CAAAM,MAAQ,CAACA,CAAI,GACtCC,IAASC,EAAY,MAAM;AAC7B,IAAKP,EAAO,SAAA;AAAA,EAChB,GAAG,CAACA,EAAO,MAAM,CAAC;AAElB,SAAO;AAAA,IACH,QAAAF;AAAA,IACA,MAAAI;AAAA,IACA,OAAAC;AAAA,IACA,QAAAC;AAAA,IACA,QAAAE;AAAA,IACA,cAAAb;AAAA,IACA,kBAAkBG;AAAA,IAClB,cAAcI,EAAO,OAAO;AAAA,IAC5B,kBAAkBA,EAAO,WAAW;AAAA,EAAA;AAE5C;"}
|