react-native-gtkx 0.3.0-alpha.1 → 0.4.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/adw/index.d.ts +3 -2
- package/dist/adw/index.js +21 -4
- package/dist/adw/index.js.map +1 -1
- package/dist/adw/widgets.generated.d.ts +1 -1
- package/dist/adw/widgets.generated.js +2 -2
- package/dist/adw/widgets.generated.js.map +1 -1
- package/dist/animated/create-animated.d.ts +2 -0
- package/dist/animated/create-animated.js +2 -0
- package/dist/animated/create-animated.js.map +1 -1
- package/dist/animated/event.d.ts +15 -0
- package/dist/animated/event.js +80 -0
- package/dist/animated/event.js.map +1 -0
- package/dist/animated/index.d.ts +4 -0
- package/dist/animated/index.js +8 -0
- package/dist/animated/index.js.map +1 -1
- package/dist/animated/spring.d.ts +10 -0
- package/dist/animated/spring.js +20 -6
- package/dist/animated/spring.js.map +1 -1
- package/dist/animated/timing.d.ts +10 -0
- package/dist/animated/timing.js +21 -13
- package/dist/animated/timing.js.map +1 -1
- package/dist/apis/host.gtkx.js +70 -11
- package/dist/apis/host.gtkx.js.map +1 -1
- package/dist/common/navigation-stack.d.ts +6 -3
- package/dist/common/navigation-stack.js +8 -1
- package/dist/common/navigation-stack.js.map +1 -1
- package/dist/common/widget.js +2 -11
- package/dist/common/widget.js.map +1 -1
- package/dist/components/animated.d.ts +1 -0
- package/dist/components/animated.js +28 -4
- package/dist/components/animated.js.map +1 -1
- package/dist/components/app-registry.js +32 -8
- package/dist/components/app-registry.js.map +1 -1
- package/dist/components/request-animation-frame.d.ts +33 -0
- package/dist/components/request-animation-frame.js +83 -0
- package/dist/components/request-animation-frame.js.map +1 -0
- package/dist/components/scroll-view.js +60 -2
- package/dist/components/scroll-view.js.map +1 -1
- package/dist/components/virtualized-list.js +1 -4
- package/dist/components/virtualized-list.js.map +1 -1
- package/dist/dnd/autoscroll.d.ts +44 -0
- package/dist/dnd/autoscroll.js +176 -0
- package/dist/dnd/autoscroll.js.map +1 -0
- package/dist/dnd/grid-order.d.ts +45 -0
- package/dist/dnd/grid-order.js +151 -0
- package/dist/dnd/grid-order.js.map +1 -0
- package/dist/dnd/grid.d.ts +44 -0
- package/dist/dnd/grid.js +397 -0
- package/dist/dnd/grid.js.map +1 -0
- package/dist/dnd/gtk-controllers.d.ts +16 -2
- package/dist/dnd/gtk-controllers.js +23 -3
- package/dist/dnd/gtk-controllers.js.map +1 -1
- package/dist/dnd/index.d.ts +4 -2
- package/dist/dnd/index.js +9 -2
- package/dist/dnd/index.js.map +1 -1
- package/dist/dnd/order-state.d.ts +14 -0
- package/dist/dnd/order-state.js +55 -0
- package/dist/dnd/order-state.js.map +1 -0
- package/dist/dnd/order.d.ts +19 -0
- package/dist/dnd/order.js +19 -0
- package/dist/dnd/order.js.map +1 -1
- package/dist/dnd/sortable.d.ts +29 -4
- package/dist/dnd/sortable.js +308 -115
- package/dist/dnd/sortable.js.map +1 -1
- package/dist/dnd/types.d.ts +236 -14
- package/dist/dnd/types.js +30 -0
- package/dist/dnd/types.js.map +1 -1
- package/dist/gesture-handler-compat/attach-context.d.ts +29 -0
- package/dist/gesture-handler-compat/attach-context.js +90 -0
- package/dist/gesture-handler-compat/attach-context.js.map +1 -0
- package/dist/gesture-handler-compat/detector-runtime.d.ts +14 -3
- package/dist/gesture-handler-compat/detector-runtime.js +15 -5
- package/dist/gesture-handler-compat/detector-runtime.js.map +1 -1
- package/dist/gesture-handler-compat/detector.js +57 -2
- package/dist/gesture-handler-compat/detector.js.map +1 -1
- package/dist/gesture-handler-compat/gesture-state-manager.d.ts +5 -0
- package/dist/gesture-handler-compat/gesture-state-manager.js +77 -0
- package/dist/gesture-handler-compat/gesture-state-manager.js.map +1 -0
- package/dist/gesture-handler-compat/index.d.ts +2 -2
- package/dist/gesture-handler-compat/index.js +38 -33
- package/dist/gesture-handler-compat/index.js.map +1 -1
- package/dist/gesture-handler-compat/recognizer.d.ts +12 -1
- package/dist/gesture-handler-compat/recognizer.js +23 -9
- package/dist/gesture-handler-compat/recognizer.js.map +1 -1
- package/dist/gesture-handler-compat/tag-registry.d.ts +14 -0
- package/dist/gesture-handler-compat/tag-registry.js +19 -0
- package/dist/gesture-handler-compat/tag-registry.js.map +1 -0
- package/dist/globals/index.d.ts +47 -0
- package/dist/globals/index.js +181 -0
- package/dist/globals/index.js.map +1 -0
- package/dist/globals/install.d.ts +1 -0
- package/dist/globals/install.js +14 -0
- package/dist/globals/install.js.map +1 -0
- package/dist/gtkx/bridge/adw-namespace.d.ts +2 -0
- package/dist/gtkx/bridge/adw-namespace.js +26 -0
- package/dist/gtkx/bridge/adw-namespace.js.map +1 -0
- package/dist/gtkx/bridge/adw.d.ts +23 -0
- package/dist/gtkx/bridge/adw.js +93 -0
- package/dist/gtkx/bridge/adw.js.map +1 -0
- package/dist/gtkx/bridge/color-scheme-parse.d.ts +11 -0
- package/dist/gtkx/bridge/color-scheme-parse.js +42 -0
- package/dist/gtkx/bridge/color-scheme-parse.js.map +1 -0
- package/dist/gtkx/bridge/color-scheme-portal.d.ts +24 -0
- package/dist/gtkx/bridge/color-scheme-portal.js +172 -0
- package/dist/gtkx/bridge/color-scheme-portal.js.map +1 -0
- package/dist/gtkx/bridge/core.d.ts +25 -0
- package/dist/gtkx/bridge/core.js +69 -0
- package/dist/gtkx/bridge/core.js.map +1 -0
- package/dist/gtkx/bridge/drag-layer.d.ts +27 -0
- package/dist/gtkx/bridge/drag-layer.js +177 -0
- package/dist/gtkx/bridge/drag-layer.js.map +1 -0
- package/dist/gtkx/bridge/index.d.ts +1 -27
- package/dist/gtkx/bridge/index.js +12 -71
- package/dist/gtkx/bridge/index.js.map +1 -1
- package/dist/gtkx/bridge/widgets.generated.adw.d.ts +1 -0
- package/dist/gtkx/bridge/widgets.generated.adw.js +16 -0
- package/dist/gtkx/bridge/widgets.generated.adw.js.map +1 -0
- package/dist/gtkx/bridge/widgets.generated.d.ts +0 -1
- package/dist/gtkx/bridge/widgets.generated.js +3 -3
- package/dist/gtkx/bridge/widgets.generated.js.map +1 -1
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/data/generated.d.ts +41 -20
- package/dist/mcp/data/generated.js +46 -20
- package/dist/mcp/data/generated.js.map +1 -1
- package/dist/metro/index.d.ts +1 -0
- package/dist/metro/index.js +12 -0
- package/dist/metro/index.js.map +1 -1
- package/dist/navigation/sidebar.js +2 -45
- package/dist/navigation/sidebar.js.map +1 -1
- package/dist/reanimated-compat/animatable-value.d.ts +158 -0
- package/dist/reanimated-compat/animatable-value.js +316 -0
- package/dist/reanimated-compat/animatable-value.js.map +1 -0
- package/dist/reanimated-compat/animation.d.ts +34 -13
- package/dist/reanimated-compat/animation.js +97 -25
- package/dist/reanimated-compat/animation.js.map +1 -1
- package/dist/reanimated-compat/mutable.js +6 -6
- package/dist/reanimated-compat/mutable.js.map +1 -1
- package/dist/reanimated-compat/updater-animations.js +32 -12
- package/dist/reanimated-compat/updater-animations.js.map +1 -1
- package/dist/runner/host-dev.js +5 -1
- package/dist/runner/host-dev.js.map +1 -1
- package/dist/runner/host.js +9 -1
- package/dist/runner/host.js.map +1 -1
- package/dist/vite/index.js +130 -0
- package/dist/vite/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/gtkx/bridge/theme.d.ts +0 -4
- package/dist/gtkx/bridge/theme.js +0 -5
- package/dist/gtkx/bridge/theme.js.map +0 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { GridDimensions, GridOrientation, GridPosition, GridPositions, SortableData } from "./types";
|
|
2
|
+
export declare const calculateGridPosition: (index: number, dimensions: GridDimensions, orientation: GridOrientation) => GridPosition;
|
|
3
|
+
export declare const calculateIndexFromRowColumn: (row: number, column: number, dimensions: GridDimensions, orientation: GridOrientation) => number;
|
|
4
|
+
/** `["a", "b"]` → `{ a: {index: 0, ...}, b: {index: 1, ...} }`. Upstream's
|
|
5
|
+
* takes objects with an `id`; both shapes are accepted so no call site has
|
|
6
|
+
* to convert. */
|
|
7
|
+
export declare const listToGridObject: <T extends SortableData>(list: readonly (string | T)[], dimensions: GridDimensions, orientation: GridOrientation) => GridPositions;
|
|
8
|
+
export declare const clamp: (value: number, min: number, max: number) => number;
|
|
9
|
+
export declare const getGridCellFromCoordinates: (x: number, y: number, dimensions: GridDimensions, orientation: GridOrientation, totalItems: number) => {
|
|
10
|
+
row: number;
|
|
11
|
+
column: number;
|
|
12
|
+
index: number;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Resolves a TRACKED cell rect (`grid.tsx`'s `useGridSortable`: the cell's
|
|
16
|
+
* own top-left, `calculateGridPosition(fromIndex, ...)` plus the pointer's
|
|
17
|
+
* delta since the drag began — never a measured layout) onto the nearest
|
|
18
|
+
* cell, ROUNDING rather than flooring both axes.
|
|
19
|
+
*
|
|
20
|
+
* The 2-D sibling of `resolveTrackedIndex` in `order.ts` — see its comment
|
|
21
|
+
* for why rounding this exact quantity is mathematically the same as
|
|
22
|
+
* resolving by the dragged cell's own CENTRE against each slot's centre,
|
|
23
|
+
* regardless of `columnGap`/`rowGap`, rather than `getGridCellFromCoordinates`'s
|
|
24
|
+
* OWN top-left floor above (upstream's own behaviour, kept faithfully there
|
|
25
|
+
* — this is a DIFFERENT function, the mirror's own live reorder trigger, not
|
|
26
|
+
* a replacement for it).
|
|
27
|
+
*/
|
|
28
|
+
export declare const resolveTrackedGridIndex: (trackedX: number, trackedY: number, dimensions: GridDimensions, orientation: GridOrientation, totalItems: number) => number;
|
|
29
|
+
/** Every id shifts by one slot between the dragged item's old and new index
|
|
30
|
+
* (`Insert` strategy) — the same "make room" reorder `Sortable`'s own
|
|
31
|
+
* `objectMove` does for a plain list, generalised to row/column. */
|
|
32
|
+
export declare const reorderGridInsert: (positions: GridPositions, activeId: string, targetIndex: number, dimensions: GridDimensions, orientation: GridOrientation) => GridPositions;
|
|
33
|
+
/** Only the two cells trade places — nobody else moves. */
|
|
34
|
+
export declare const reorderGridSwap: (positions: GridPositions, activeId: string, targetId: string, dimensions: GridDimensions, orientation: GridOrientation) => GridPositions;
|
|
35
|
+
export declare const calculateGridContentDimensions: (itemsCount: number, dimensions: GridDimensions, orientation: GridOrientation) => {
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
};
|
|
39
|
+
export declare const findItemIdAtIndex: (positions: GridPositions, index: number) => string | null;
|
|
40
|
+
/** `GridPositions` → an order array sorted by `.index`, which is the
|
|
41
|
+
* representation `SortableGrid`/`useGridSortableList` actually keep as
|
|
42
|
+
* React state (see order-state.ts) — deriving it back from a `GridPositions`
|
|
43
|
+
* map is what lets a reorder decision go through `reorderGridInsert` /
|
|
44
|
+
* `reorderGridSwap` unchanged rather than a second, hand-rolled splice. */
|
|
45
|
+
export declare const gridPositionsToOrder: (positions: GridPositions) => string[];
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
const GRID_ORIENTATION_HORIZONTAL = "horizontal";
|
|
2
|
+
export const calculateGridPosition = (index, dimensions, orientation) => {
|
|
3
|
+
const { columns = 3, rows = 3, itemWidth, itemHeight, rowGap = 0, columnGap = 0, } = dimensions;
|
|
4
|
+
let row;
|
|
5
|
+
let column;
|
|
6
|
+
if (orientation === GRID_ORIENTATION_HORIZONTAL) {
|
|
7
|
+
column = Math.floor(index / rows);
|
|
8
|
+
row = index % rows;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
row = Math.floor(index / columns);
|
|
12
|
+
column = index % columns;
|
|
13
|
+
}
|
|
14
|
+
const x = column * (itemWidth + columnGap);
|
|
15
|
+
const y = row * (itemHeight + rowGap);
|
|
16
|
+
return { index, row, column, x, y };
|
|
17
|
+
};
|
|
18
|
+
export const calculateIndexFromRowColumn = (row, column, dimensions, orientation) => {
|
|
19
|
+
const { columns = 3, rows = 3 } = dimensions;
|
|
20
|
+
return orientation === GRID_ORIENTATION_HORIZONTAL
|
|
21
|
+
? column * rows + row
|
|
22
|
+
: row * columns + column;
|
|
23
|
+
};
|
|
24
|
+
/** `["a", "b"]` → `{ a: {index: 0, ...}, b: {index: 1, ...} }`. Upstream's
|
|
25
|
+
* takes objects with an `id`; both shapes are accepted so no call site has
|
|
26
|
+
* to convert. */
|
|
27
|
+
export const listToGridObject = (list, dimensions, orientation) => {
|
|
28
|
+
const positions = {};
|
|
29
|
+
list.forEach((item, index) => {
|
|
30
|
+
const id = typeof item === "string" ? item : item.id;
|
|
31
|
+
positions[id] = calculateGridPosition(index, dimensions, orientation);
|
|
32
|
+
});
|
|
33
|
+
return positions;
|
|
34
|
+
};
|
|
35
|
+
export const clamp = (value, min, max) => Math.max(min, Math.min(value, max));
|
|
36
|
+
export const getGridCellFromCoordinates = (x, y, dimensions, orientation, totalItems) => {
|
|
37
|
+
const { itemWidth, itemHeight, rowGap = 0, columnGap = 0 } = dimensions;
|
|
38
|
+
const column = Math.floor(x / (itemWidth + columnGap));
|
|
39
|
+
const row = Math.floor(y / (itemHeight + rowGap));
|
|
40
|
+
const index = calculateIndexFromRowColumn(row, column, dimensions, orientation);
|
|
41
|
+
const clampedIndex = clamp(index, 0, totalItems - 1);
|
|
42
|
+
const clampedPosition = calculateGridPosition(clampedIndex, dimensions, orientation);
|
|
43
|
+
return {
|
|
44
|
+
row: clampedPosition.row,
|
|
45
|
+
column: clampedPosition.column,
|
|
46
|
+
index: clampedIndex,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Resolves a TRACKED cell rect (`grid.tsx`'s `useGridSortable`: the cell's
|
|
51
|
+
* own top-left, `calculateGridPosition(fromIndex, ...)` plus the pointer's
|
|
52
|
+
* delta since the drag began — never a measured layout) onto the nearest
|
|
53
|
+
* cell, ROUNDING rather than flooring both axes.
|
|
54
|
+
*
|
|
55
|
+
* The 2-D sibling of `resolveTrackedIndex` in `order.ts` — see its comment
|
|
56
|
+
* for why rounding this exact quantity is mathematically the same as
|
|
57
|
+
* resolving by the dragged cell's own CENTRE against each slot's centre,
|
|
58
|
+
* regardless of `columnGap`/`rowGap`, rather than `getGridCellFromCoordinates`'s
|
|
59
|
+
* OWN top-left floor above (upstream's own behaviour, kept faithfully there
|
|
60
|
+
* — this is a DIFFERENT function, the mirror's own live reorder trigger, not
|
|
61
|
+
* a replacement for it).
|
|
62
|
+
*/
|
|
63
|
+
export const resolveTrackedGridIndex = (trackedX, trackedY, dimensions, orientation, totalItems) => {
|
|
64
|
+
const { itemWidth, itemHeight, rowGap = 0, columnGap = 0 } = dimensions;
|
|
65
|
+
const column = Math.round(trackedX / (itemWidth + columnGap));
|
|
66
|
+
const row = Math.round(trackedY / (itemHeight + rowGap));
|
|
67
|
+
const index = calculateIndexFromRowColumn(row, column, dimensions, orientation);
|
|
68
|
+
return clamp(index, 0, totalItems - 1);
|
|
69
|
+
};
|
|
70
|
+
/** Every id shifts by one slot between the dragged item's old and new index
|
|
71
|
+
* (`Insert` strategy) — the same "make room" reorder `Sortable`'s own
|
|
72
|
+
* `objectMove` does for a plain list, generalised to row/column. */
|
|
73
|
+
export const reorderGridInsert = (positions, activeId, targetIndex, dimensions, orientation) => {
|
|
74
|
+
const newPositions = {};
|
|
75
|
+
const activePosition = positions[activeId];
|
|
76
|
+
if (!activePosition) {
|
|
77
|
+
return positions;
|
|
78
|
+
}
|
|
79
|
+
const fromIndex = activePosition.index;
|
|
80
|
+
if (fromIndex === targetIndex) {
|
|
81
|
+
return positions;
|
|
82
|
+
}
|
|
83
|
+
const movingUp = targetIndex < fromIndex;
|
|
84
|
+
for (const id in positions) {
|
|
85
|
+
const currentIndex = positions[id].index;
|
|
86
|
+
if (id === activeId) {
|
|
87
|
+
newPositions[id] = calculateGridPosition(targetIndex, dimensions, orientation);
|
|
88
|
+
}
|
|
89
|
+
else if (movingUp &&
|
|
90
|
+
currentIndex >= targetIndex &&
|
|
91
|
+
currentIndex < fromIndex) {
|
|
92
|
+
newPositions[id] = calculateGridPosition(currentIndex + 1, dimensions, orientation);
|
|
93
|
+
}
|
|
94
|
+
else if (!movingUp &&
|
|
95
|
+
currentIndex <= targetIndex &&
|
|
96
|
+
currentIndex > fromIndex) {
|
|
97
|
+
newPositions[id] = calculateGridPosition(currentIndex - 1, dimensions, orientation);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
newPositions[id] = positions[id];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return newPositions;
|
|
104
|
+
};
|
|
105
|
+
/* eslint-disable @typescript-eslint/no-unused-vars --
|
|
106
|
+
`dimensions`/`orientation` keep `reorderGridSwap` the same shape as
|
|
107
|
+
`reorderGridInsert`, which needs both to recompute a shifted cell's
|
|
108
|
+
row/column — a straight swap of two existing `GridPosition` objects needs
|
|
109
|
+
no arithmetic at all. */
|
|
110
|
+
/** Only the two cells trade places — nobody else moves. */
|
|
111
|
+
export const reorderGridSwap = (positions, activeId, targetId, dimensions, orientation) => {
|
|
112
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
113
|
+
const activePosition = positions[activeId];
|
|
114
|
+
const targetPosition = positions[targetId];
|
|
115
|
+
if (!activePosition || !targetPosition) {
|
|
116
|
+
return positions;
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
...positions,
|
|
120
|
+
[activeId]: targetPosition,
|
|
121
|
+
[targetId]: activePosition,
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
export const calculateGridContentDimensions = (itemsCount, dimensions, orientation) => {
|
|
125
|
+
const { columns = 3, rows = 3, itemWidth, itemHeight, rowGap = 0, columnGap = 0, } = dimensions;
|
|
126
|
+
if (orientation === GRID_ORIENTATION_HORIZONTAL) {
|
|
127
|
+
const totalColumns = Math.ceil(itemsCount / rows);
|
|
128
|
+
const width = totalColumns * itemWidth + (totalColumns - 1) * columnGap;
|
|
129
|
+
const height = rows * itemHeight + (rows - 1) * rowGap;
|
|
130
|
+
return { width, height };
|
|
131
|
+
}
|
|
132
|
+
const totalRows = Math.ceil(itemsCount / columns);
|
|
133
|
+
const width = columns * itemWidth + (columns - 1) * columnGap;
|
|
134
|
+
const height = totalRows * itemHeight + (totalRows - 1) * rowGap;
|
|
135
|
+
return { width, height };
|
|
136
|
+
};
|
|
137
|
+
export const findItemIdAtIndex = (positions, index) => {
|
|
138
|
+
for (const id in positions) {
|
|
139
|
+
if (positions[id].index === index) {
|
|
140
|
+
return id;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
144
|
+
};
|
|
145
|
+
/** `GridPositions` → an order array sorted by `.index`, which is the
|
|
146
|
+
* representation `SortableGrid`/`useGridSortableList` actually keep as
|
|
147
|
+
* React state (see order-state.ts) — deriving it back from a `GridPositions`
|
|
148
|
+
* map is what lets a reorder decision go through `reorderGridInsert` /
|
|
149
|
+
* `reorderGridSwap` unchanged rather than a second, hand-rolled splice. */
|
|
150
|
+
export const gridPositionsToOrder = (positions) => Object.keys(positions).sort((left, right) => positions[left].index - positions[right].index);
|
|
151
|
+
//# sourceMappingURL=grid-order.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grid-order.js","sourceRoot":"","sources":["../../src/dnd/grid-order.ts"],"names":[],"mappings":"AAkBA,MAAM,2BAA2B,GAAG,YAAY,CAAA;AAEhD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,KAAa,EACb,UAA0B,EAC1B,WAA4B,EACd,EAAE;IAChB,MAAM,EACJ,OAAO,GAAG,CAAC,EACX,IAAI,GAAG,CAAC,EACR,SAAS,EACT,UAAU,EACV,MAAM,GAAG,CAAC,EACV,SAAS,GAAG,CAAC,GACd,GAAG,UAAU,CAAA;IACd,IAAI,GAAW,CAAA;IACf,IAAI,MAAc,CAAA;IAClB,IAAK,WAAsB,KAAK,2BAA2B,EAAE,CAAC;QAC5D,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,CAAA;QACjC,GAAG,GAAG,KAAK,GAAG,IAAI,CAAA;IACpB,CAAC;SAAM,CAAC;QACN,GAAG,GAAG,IAAI,CAAC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IAAI,CAAC,CAAA;QACjD,MAAM,KAAK,GAAG,YAAY,GAAG,SAAS,GAAG,CAAC,YAAY,GAAG,CAAC,CAAC,GAAG,SAAS,CAAA;QACvE,MAAM,MAAM,GAAG,IAAI,GAAG,UAAU,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,CAAA;QACtD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA;IAC1B,CAAC;IACD,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,CAAA;IACjD,MAAM,KAAK,GAAG,OAAO,GAAG,SAAS,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,GAAG,SAAS,CAAA;IAC7D,MAAM,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC,GAAG,MAAM,CAAA;IAChE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAA;AAC1B,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,SAAwB,EACxB,KAAa,EACE,EAAE;IACjB,KAAK,MAAM,EAAE,IAAI,SAAS,EAAE,CAAC;QAC3B,IAAI,SAAS,CAAC,EAAE,CAAE,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;YACnC,OAAO,EAAE,CAAA;QACX,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED;;;;4EAI4E;AAC5E,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,SAAwB,EAAY,EAAE,CACzE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CACzB,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAE,CAAC,KAAK,GAAG,SAAS,CAAC,KAAK,CAAE,CAAC,KAAK,CAClE,CAAA","sourcesContent":["// The grid arithmetic, ported from upstream's `utils/gridCalculations`\n// (worklets there, plain functions here — same reasoning as order.ts) and\n// kept free of every GTK import, so the unit test project can exercise it\n// without a display.\n//\n// `getGridCellFromCoordinates` FLOORS both axes onto the cell whose top-left\n// corner is at or before the point — that is upstream's own behaviour\n// (`Math.floor(x / (itemWidth + columnGap))`), not a bug this port fixes. A\n// point one pixel into a cell resolves to that cell, one pixel before it to\n// the previous one; there is no \"nearest\" rounding anywhere in the original.\nimport type {\n GridDimensions,\n GridOrientation,\n GridPosition,\n GridPositions,\n SortableData,\n} from \"./types\"\n\nconst GRID_ORIENTATION_HORIZONTAL = \"horizontal\"\n\nexport const calculateGridPosition = (\n index: number,\n dimensions: GridDimensions,\n orientation: GridOrientation,\n): GridPosition => {\n const {\n columns = 3,\n rows = 3,\n itemWidth,\n itemHeight,\n rowGap = 0,\n columnGap = 0,\n } = dimensions\n let row: number\n let column: number\n if ((orientation as string) === GRID_ORIENTATION_HORIZONTAL) {\n column = Math.floor(index / rows)\n row = index % rows\n } else {\n row = Math.floor(index / columns)\n column = index % columns\n }\n const x = column * (itemWidth + columnGap)\n const y = row * (itemHeight + rowGap)\n return { index, row, column, x, y }\n}\n\nexport const calculateIndexFromRowColumn = (\n row: number,\n column: number,\n dimensions: GridDimensions,\n orientation: GridOrientation,\n): number => {\n const { columns = 3, rows = 3 } = dimensions\n return (orientation as string) === GRID_ORIENTATION_HORIZONTAL\n ? column * rows + row\n : row * columns + column\n}\n\n/** `[\"a\", \"b\"]` → `{ a: {index: 0, ...}, b: {index: 1, ...} }`. Upstream's\n * takes objects with an `id`; both shapes are accepted so no call site has\n * to convert. */\nexport const listToGridObject = <T extends SortableData>(\n list: readonly (string | T)[],\n dimensions: GridDimensions,\n orientation: GridOrientation,\n): GridPositions => {\n const positions: GridPositions = {}\n list.forEach((item, index) => {\n const id = typeof item === \"string\" ? item : item.id\n positions[id] = calculateGridPosition(index, dimensions, orientation)\n })\n return positions\n}\n\nexport const clamp = (value: number, min: number, max: number): number =>\n Math.max(min, Math.min(value, max))\n\nexport const getGridCellFromCoordinates = (\n x: number,\n y: number,\n dimensions: GridDimensions,\n orientation: GridOrientation,\n totalItems: number,\n): { row: number; column: number; index: number } => {\n const { itemWidth, itemHeight, rowGap = 0, columnGap = 0 } = dimensions\n const column = Math.floor(x / (itemWidth + columnGap))\n const row = Math.floor(y / (itemHeight + rowGap))\n const index = calculateIndexFromRowColumn(\n row,\n column,\n dimensions,\n orientation,\n )\n const clampedIndex = clamp(index, 0, totalItems - 1)\n const clampedPosition = calculateGridPosition(\n clampedIndex,\n dimensions,\n orientation,\n )\n return {\n row: clampedPosition.row,\n column: clampedPosition.column,\n index: clampedIndex,\n }\n}\n\n/**\n * Resolves a TRACKED cell rect (`grid.tsx`'s `useGridSortable`: the cell's\n * own top-left, `calculateGridPosition(fromIndex, ...)` plus the pointer's\n * delta since the drag began — never a measured layout) onto the nearest\n * cell, ROUNDING rather than flooring both axes.\n *\n * The 2-D sibling of `resolveTrackedIndex` in `order.ts` — see its comment\n * for why rounding this exact quantity is mathematically the same as\n * resolving by the dragged cell's own CENTRE against each slot's centre,\n * regardless of `columnGap`/`rowGap`, rather than `getGridCellFromCoordinates`'s\n * OWN top-left floor above (upstream's own behaviour, kept faithfully there\n * — this is a DIFFERENT function, the mirror's own live reorder trigger, not\n * a replacement for it).\n */\nexport const resolveTrackedGridIndex = (\n trackedX: number,\n trackedY: number,\n dimensions: GridDimensions,\n orientation: GridOrientation,\n totalItems: number,\n): number => {\n const { itemWidth, itemHeight, rowGap = 0, columnGap = 0 } = dimensions\n const column = Math.round(trackedX / (itemWidth + columnGap))\n const row = Math.round(trackedY / (itemHeight + rowGap))\n const index = calculateIndexFromRowColumn(\n row,\n column,\n dimensions,\n orientation,\n )\n return clamp(index, 0, totalItems - 1)\n}\n\n/** Every id shifts by one slot between the dragged item's old and new index\n * (`Insert` strategy) — the same \"make room\" reorder `Sortable`'s own\n * `objectMove` does for a plain list, generalised to row/column. */\nexport const reorderGridInsert = (\n positions: GridPositions,\n activeId: string,\n targetIndex: number,\n dimensions: GridDimensions,\n orientation: GridOrientation,\n): GridPositions => {\n const newPositions: GridPositions = {}\n const activePosition = positions[activeId]\n if (!activePosition) {\n return positions\n }\n const fromIndex = activePosition.index\n if (fromIndex === targetIndex) {\n return positions\n }\n const movingUp = targetIndex < fromIndex\n for (const id in positions) {\n const currentIndex = positions[id]!.index\n if (id === activeId) {\n newPositions[id] = calculateGridPosition(\n targetIndex,\n dimensions,\n orientation,\n )\n } else if (\n movingUp &&\n currentIndex >= targetIndex &&\n currentIndex < fromIndex\n ) {\n newPositions[id] = calculateGridPosition(\n currentIndex + 1,\n dimensions,\n orientation,\n )\n } else if (\n !movingUp &&\n currentIndex <= targetIndex &&\n currentIndex > fromIndex\n ) {\n newPositions[id] = calculateGridPosition(\n currentIndex - 1,\n dimensions,\n orientation,\n )\n } else {\n newPositions[id] = positions[id]!\n }\n }\n return newPositions\n}\n\n/* eslint-disable @typescript-eslint/no-unused-vars --\n `dimensions`/`orientation` keep `reorderGridSwap` the same shape as\n `reorderGridInsert`, which needs both to recompute a shifted cell's\n row/column — a straight swap of two existing `GridPosition` objects needs\n no arithmetic at all. */\n/** Only the two cells trade places — nobody else moves. */\nexport const reorderGridSwap = (\n positions: GridPositions,\n activeId: string,\n targetId: string,\n dimensions: GridDimensions,\n orientation: GridOrientation,\n): GridPositions => {\n /* eslint-enable @typescript-eslint/no-unused-vars */\n const activePosition = positions[activeId]\n const targetPosition = positions[targetId]\n if (!activePosition || !targetPosition) {\n return positions\n }\n return {\n ...positions,\n [activeId]: targetPosition,\n [targetId]: activePosition,\n }\n}\n\nexport const calculateGridContentDimensions = (\n itemsCount: number,\n dimensions: GridDimensions,\n orientation: GridOrientation,\n): { width: number; height: number } => {\n const {\n columns = 3,\n rows = 3,\n itemWidth,\n itemHeight,\n rowGap = 0,\n columnGap = 0,\n } = dimensions\n if ((orientation as string) === GRID_ORIENTATION_HORIZONTAL) {\n const totalColumns = Math.ceil(itemsCount / rows)\n const width = totalColumns * itemWidth + (totalColumns - 1) * columnGap\n const height = rows * itemHeight + (rows - 1) * rowGap\n return { width, height }\n }\n const totalRows = Math.ceil(itemsCount / columns)\n const width = columns * itemWidth + (columns - 1) * columnGap\n const height = totalRows * itemHeight + (totalRows - 1) * rowGap\n return { width, height }\n}\n\nexport const findItemIdAtIndex = (\n positions: GridPositions,\n index: number,\n): string | null => {\n for (const id in positions) {\n if (positions[id]!.index === index) {\n return id\n }\n }\n return null\n}\n\n/** `GridPositions` → an order array sorted by `.index`, which is the\n * representation `SortableGrid`/`useGridSortableList` actually keep as\n * React state (see order-state.ts) — deriving it back from a `GridPositions`\n * map is what lets a reorder decision go through `reorderGridInsert` /\n * `reorderGridSwap` unchanged rather than a second, hand-rolled splice. */\nexport const gridPositionsToOrder = (positions: GridPositions): string[] =>\n Object.keys(positions).sort(\n (left, right) => positions[left]!.index - positions[right]!.index,\n )\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type SortableData, type SortableGridItemProps, type SortableGridProps, type UseGridSortableListOptions, type UseGridSortableListReturn, type UseGridSortableOptions, type UseGridSortableReturn } from "./types";
|
|
3
|
+
export { calculateGridContentDimensions, calculateGridPosition, calculateIndexFromRowColumn, findItemIdAtIndex, getGridCellFromCoordinates, listToGridObject, reorderGridInsert, reorderGridSwap, } from "./grid-order";
|
|
4
|
+
/**
|
|
5
|
+
* Owns the order of a sortable grid, for an app rendering its own container —
|
|
6
|
+
* the grid's counterpart of `useSortableList`. **The order half only**, same
|
|
7
|
+
* contract: rows still need to sit inside a `SortableGrid` for the drag
|
|
8
|
+
* wiring, which travels through context. No autoscroll wiring either, for
|
|
9
|
+
* the same reason `useSortableList` has none — this hook builds no
|
|
10
|
+
* `ScrollView` of its own.
|
|
11
|
+
*/
|
|
12
|
+
export declare const useGridSortableList: <TData extends SortableData>(options: UseGridSortableListOptions<TData>) => UseGridSortableListReturn<TData>;
|
|
13
|
+
/**
|
|
14
|
+
* A grid whose cells reorder by dragging.
|
|
15
|
+
*
|
|
16
|
+
* ```tsx
|
|
17
|
+
* <SortableGrid
|
|
18
|
+
* data={photos}
|
|
19
|
+
* dimensions={{ columns: 3, itemWidth: 100, itemHeight: 100, columnGap: 8, rowGap: 8 }}
|
|
20
|
+
* renderItem={({ item, id, ...rest }) => (
|
|
21
|
+
* <SortableGridItem key={id} id={id} data={item} {...rest}>
|
|
22
|
+
* <Image source={{ uri: item.uri }} style={{ flex: 1 }} />
|
|
23
|
+
* </SortableGridItem>
|
|
24
|
+
* )}
|
|
25
|
+
* />
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* No list-level `onMove`/`onDragStart`/`onDrop`/`onDragging` — same as
|
|
29
|
+
* upstream's own `SortableGridProps`, which carries none either; wire them on
|
|
30
|
+
* each `SortableGridItem` instead.
|
|
31
|
+
*/
|
|
32
|
+
export declare const SortableGrid: <TData extends SortableData>({ data, renderItem, dimensions, orientation, strategy, style, contentContainerStyle, itemKeyExtractor, testID, }: SortableGridProps<TData>) => ReactNode;
|
|
33
|
+
/**
|
|
34
|
+
* The reorder half of the module, as a hook, for a cell that owns its own
|
|
35
|
+
* view.
|
|
36
|
+
*/
|
|
37
|
+
export declare const useGridSortable: <TData>(options: UseGridSortableOptions<TData>) => UseGridSortableReturn;
|
|
38
|
+
/** One cell of a {@link SortableGrid}. Both a drag source and a drop target:
|
|
39
|
+
* the cell you drag onto is the position the dragged cell takes (or trades
|
|
40
|
+
* with, under `GridStrategy.Swap`). */
|
|
41
|
+
export declare const SortableGridItem: {
|
|
42
|
+
<TData>({ id, data, dimensions, children, style, animatedStyle, testID, onMove, onDragStart, onDrop, onDragging, }: SortableGridItemProps<TData>): ReactNode;
|
|
43
|
+
Handle: ({ children, style, testID, }: import("./types").DraggableHandleProps) => ReactNode;
|
|
44
|
+
};
|