react-crud-mobile 1.3.369 → 1.3.373
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/elements/core/UIDraggableList.d.ts +3 -0
- package/dist/react-crud-mobile.cjs.development.js +209 -141
- package/dist/react-crud-mobile.cjs.development.js.map +1 -1
- package/dist/react-crud-mobile.cjs.production.min.js +1 -1
- package/dist/react-crud-mobile.cjs.production.min.js.map +1 -1
- package/dist/react-crud-mobile.esm.js +210 -141
- package/dist/react-crud-mobile.esm.js.map +1 -1
- package/package.json +3 -4
- package/src/elements/core/UIDraggableList.tsx +255 -0
- package/src/elements/core/UIOrder.tsx +228 -167
@@ -15,8 +15,6 @@ var Slider = _interopDefault(require('@react-native-community/slider'));
|
|
15
15
|
var Toast = require('react-native-toast-message');
|
16
16
|
var Toast__default = _interopDefault(Toast);
|
17
17
|
var reactNativeGestureHandler = require('react-native-gesture-handler');
|
18
|
-
var DraggableFlatList = require('react-native-draggable-flatlist');
|
19
|
-
var DraggableFlatList__default = _interopDefault(DraggableFlatList);
|
20
18
|
var reactNativeSafeAreaContext = require('react-native-safe-area-context');
|
21
19
|
|
22
20
|
function _extends() {
|
@@ -1727,161 +1725,231 @@ var styles$9 = /*#__PURE__*/reactNative.StyleSheet.create({
|
|
1727
1725
|
view: {}
|
1728
1726
|
});
|
1729
1727
|
|
1728
|
+
var ITEM_HEIGHT = 70;
|
1730
1729
|
function UIOrder(props) {
|
1731
1730
|
var scope = props.scope;
|
1732
|
-
var
|
1733
|
-
var
|
1734
|
-
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1738
|
-
|
1739
|
-
|
1740
|
-
|
1741
|
-
|
1742
|
-
|
1743
|
-
|
1744
|
-
|
1745
|
-
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1749
|
-
|
1731
|
+
var initial = scope.getOptions();
|
1732
|
+
var _useState = React.useState(initial),
|
1733
|
+
items = _useState[0],
|
1734
|
+
setItems = _useState[1];
|
1735
|
+
var _useState2 = React.useState(null),
|
1736
|
+
draggingId = _useState2[0],
|
1737
|
+
setDraggingId = _useState2[1];
|
1738
|
+
// O tipo Animated.Value em um ambiente TypeScript puro não tem o método ._value,
|
1739
|
+
// mas é a propriedade interna usada para acessar o valor diretamente.
|
1740
|
+
// Usamos 'any' no acesso para suprimir o erro TS.
|
1741
|
+
var positions = React.useRef(Object.fromEntries(initial.map(function (it, i) {
|
1742
|
+
return [it.value, new reactNative.Animated.Value(i * ITEM_HEIGHT)];
|
1743
|
+
}))).current;
|
1744
|
+
var panRespondersRef = React.useRef({});
|
1745
|
+
var activeItem = React.useRef(null);
|
1746
|
+
var activeIndex = React.useRef(-1);
|
1747
|
+
var offsetY = React.useRef(0);
|
1748
|
+
// Armazena a lista mais recente em uma ref para uso em funções de PanResponder
|
1749
|
+
var itemsRef = React.useRef(items);
|
1750
|
+
React.useEffect(function () {
|
1751
|
+
itemsRef.current = items;
|
1752
|
+
}, [items]);
|
1753
|
+
// 1. Atualiza posições apenas para itens existentes
|
1754
|
+
React.useEffect(function () {
|
1755
|
+
items.forEach(function (it, idx) {
|
1756
|
+
if (!positions[it.value]) positions[it.value] = new reactNative.Animated.Value(idx * ITEM_HEIGHT);
|
1757
|
+
reactNative.Animated.spring(positions[it.value], {
|
1758
|
+
toValue: idx * ITEM_HEIGHT,
|
1759
|
+
useNativeDriver: false
|
1760
|
+
}).start();
|
1761
|
+
});
|
1762
|
+
}, [items]);
|
1763
|
+
var createPanResponder = function createPanResponder(item) {
|
1764
|
+
return reactNative.PanResponder.create({
|
1765
|
+
onStartShouldSetPanResponder: function onStartShouldSetPanResponder() {
|
1766
|
+
return true;
|
1767
|
+
},
|
1768
|
+
onPanResponderGrant: function onPanResponderGrant() {
|
1769
|
+
// Use itemsRef.current para obter a lista mais recente no momento do arrasto.
|
1770
|
+
var currentItems = itemsRef.current;
|
1771
|
+
if (!positions[item.value] || !currentItems.find(function (it) {
|
1772
|
+
return it.value === item.value;
|
1773
|
+
})) return;
|
1774
|
+
activeItem.current = item;
|
1775
|
+
activeIndex.current = currentItems.findIndex(function (it) {
|
1776
|
+
return it.value === item.value;
|
1750
1777
|
});
|
1751
|
-
|
1752
|
-
|
1753
|
-
|
1754
|
-
|
1755
|
-
|
1756
|
-
|
1757
|
-
|
1758
|
-
|
1759
|
-
|
1760
|
-
|
1761
|
-
|
1762
|
-
|
1763
|
-
|
1764
|
-
|
1765
|
-
|
1766
|
-
|
1767
|
-
|
1768
|
-
|
1769
|
-
|
1770
|
-
|
1771
|
-
|
1772
|
-
row = _useState[0];
|
1773
|
-
var css = _extends({}, scope.getStyle('row'));
|
1774
|
-
if (isActive) {
|
1775
|
-
css = _extends({}, css, scope.getStyle('active'));
|
1776
|
-
}
|
1777
|
-
if (isActive) {
|
1778
|
-
css = _extends({}, css, row.getStyle('rowSelected', {}));
|
1779
|
-
} else {
|
1780
|
-
css = _extends({}, css, row.getStyle('rowUnSelected', {}));
|
1781
|
-
}
|
1782
|
-
var Child = function Child() {
|
1783
|
-
if (reactCrudUtils.Utils.isEmpty(props.children)) {
|
1784
|
-
return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
1785
|
-
children: [/*#__PURE__*/jsxRuntime.jsx(vectorIcons.MaterialCommunityIcons, {
|
1786
|
-
name: "drag",
|
1787
|
-
size: 24,
|
1788
|
-
color: "black"
|
1789
|
-
}), /*#__PURE__*/jsxRuntime.jsx(reactNative.Text, {
|
1790
|
-
style: styles$a.text,
|
1791
|
-
children: scope.getItemLabel(item)
|
1792
|
-
})]
|
1778
|
+
// CORREÇÃO: Usa a propriedade interna _value para acessar o valor atual
|
1779
|
+
offsetY.current = positions[item.value]._value; // 👈 CORREÇÃO APLICADA
|
1780
|
+
setDraggingId(item.value);
|
1781
|
+
},
|
1782
|
+
onPanResponderMove: function onPanResponderMove(_, gesture) {
|
1783
|
+
var currentItems = itemsRef.current;
|
1784
|
+
if (!positions[item.value] || !currentItems.find(function (it) {
|
1785
|
+
return it.value === item.value;
|
1786
|
+
})) return;
|
1787
|
+
var y = offsetY.current + gesture.dy;
|
1788
|
+
positions[item.value].setValue(y);
|
1789
|
+
var targetIndex = Math.max(0, Math.min(currentItems.length - 1, Math.floor((y + ITEM_HEIGHT / 2) / ITEM_HEIGHT)));
|
1790
|
+
currentItems.forEach(function (other, idx) {
|
1791
|
+
if (other.value === item.value || !positions[other.value]) return;
|
1792
|
+
var targetY = idx * ITEM_HEIGHT;
|
1793
|
+
if (idx > activeIndex.current && idx <= targetIndex) targetY = (idx - 1) * ITEM_HEIGHT;else if (idx < activeIndex.current && idx >= targetIndex) targetY = (idx + 1) * ITEM_HEIGHT;
|
1794
|
+
reactNative.Animated.timing(positions[other.value], {
|
1795
|
+
toValue: targetY,
|
1796
|
+
duration: 120,
|
1797
|
+
useNativeDriver: false
|
1798
|
+
}).start();
|
1793
1799
|
});
|
1800
|
+
},
|
1801
|
+
onPanResponderRelease: function onPanResponderRelease() {
|
1802
|
+
var moved = activeItem.current;
|
1803
|
+
var currentItems = itemsRef.current;
|
1804
|
+
if (!moved || !positions[moved.value] || !currentItems.find(function (it) {
|
1805
|
+
return it.value === moved.value;
|
1806
|
+
})) return;
|
1807
|
+
// CORREÇÃO: Usa a propriedade interna _value para obter a posição final
|
1808
|
+
var finalY = positions[moved.value]._value; // 👈 CORREÇÃO APLICADA
|
1809
|
+
var newIndex = Math.max(0, Math.min(currentItems.length - 1, Math.floor((finalY + ITEM_HEIGHT / 2) / ITEM_HEIGHT)));
|
1810
|
+
var oldIndex = activeIndex.current;
|
1811
|
+
var updated = [].concat(currentItems);
|
1812
|
+
var _updated$splice = updated.splice(oldIndex, 1),
|
1813
|
+
removed = _updated$splice[0];
|
1814
|
+
updated.splice(newIndex, 0, removed);
|
1815
|
+
// Atualiza o state com a nova ordem.
|
1816
|
+
setItems(updated);
|
1817
|
+
// A animação final agora está no useEffect, mas fazemos a limpeza das refs.
|
1818
|
+
setDraggingId(null);
|
1819
|
+
activeItem.current = null;
|
1820
|
+
activeIndex.current = -1;
|
1794
1821
|
}
|
1795
|
-
return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
|
1796
|
-
children: /*#__PURE__*/jsxRuntime.jsx(UIChildren, {
|
1797
|
-
"transient": true,
|
1798
|
-
scope: row,
|
1799
|
-
crud: row.crud,
|
1800
|
-
children: props.children
|
1801
|
-
})
|
1802
|
-
});
|
1803
|
-
};
|
1804
|
-
return /*#__PURE__*/jsxRuntime.jsx(DraggableFlatList.ScaleDecorator, {
|
1805
|
-
children: /*#__PURE__*/jsxRuntime.jsx(reactNative.TouchableOpacity, {
|
1806
|
-
style: [styles$a.row, {
|
1807
|
-
backgroundColor: isActive ? 'lightblue' : 'white'
|
1808
|
-
}, _extends({}, css)],
|
1809
|
-
delayLongPress: 100,
|
1810
|
-
onLongPress: drag // Initiate drag on long press
|
1811
|
-
,
|
1812
|
-
children: /*#__PURE__*/jsxRuntime.jsx(Child, {})
|
1813
|
-
})
|
1814
1822
|
});
|
1815
1823
|
};
|
1816
|
-
|
1817
|
-
|
1818
|
-
if (
|
1819
|
-
|
1820
|
-
style: _extends({
|
1821
|
-
flex: 1,
|
1822
|
-
width: '100%'
|
1823
|
-
}, scope.getStyle('order', {
|
1824
|
-
justifyContent: 'flex-start'
|
1825
|
-
})),
|
1826
|
-
children: children
|
1827
|
-
});
|
1824
|
+
// Cria/Reusa os PanResponders
|
1825
|
+
items.forEach(function (it) {
|
1826
|
+
if (!panRespondersRef.current[it.value]) {
|
1827
|
+
panRespondersRef.current[it.value] = createPanResponder(it);
|
1828
1828
|
}
|
1829
|
-
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
1837
|
-
|
1838
|
-
|
1829
|
+
});
|
1830
|
+
var removeItem = function removeItem(id) {
|
1831
|
+
if (draggingId === id) {
|
1832
|
+
setDraggingId(null);
|
1833
|
+
activeItem.current = null;
|
1834
|
+
activeIndex.current = -1;
|
1835
|
+
}
|
1836
|
+
// CORREÇÃO: Delete a referência Animated.Value *e* a referência PanResponder
|
1837
|
+
if (positions[id]) {
|
1838
|
+
delete positions[id];
|
1839
|
+
}
|
1840
|
+
if (panRespondersRef.current[id]) {
|
1841
|
+
delete panRespondersRef.current[id];
|
1842
|
+
}
|
1843
|
+
setItems(function (prev) {
|
1844
|
+
var updated = prev.filter(function (it) {
|
1845
|
+
return it.value !== id;
|
1846
|
+
});
|
1847
|
+
// Anima os itens restantes para seus novos índices
|
1848
|
+
updated.forEach(function (it, idx) {
|
1849
|
+
if (positions[it.value]) reactNative.Animated.spring(positions[it.value], {
|
1850
|
+
toValue: idx * ITEM_HEIGHT,
|
1851
|
+
useNativeDriver: false
|
1852
|
+
}).start();
|
1853
|
+
});
|
1854
|
+
return updated;
|
1839
1855
|
});
|
1840
1856
|
};
|
1841
|
-
|
1842
|
-
|
1843
|
-
|
1844
|
-
|
1845
|
-
|
1846
|
-
|
1847
|
-
|
1848
|
-
|
1849
|
-
|
1850
|
-
ListFooterComponent: /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
|
1851
|
-
children: scope.getPart('footer')
|
1852
|
-
}),
|
1853
|
-
renderItem: renderItem,
|
1854
|
-
containerStyle: _extends({}, scope.getStyle('list')),
|
1855
|
-
keyExtractor: function keyExtractor(item) {
|
1856
|
-
var key = scope.getItemValue(item);
|
1857
|
-
if (original != null && original.debug) {
|
1858
|
-
console.log(key);
|
1859
|
-
}
|
1860
|
-
return key;
|
1857
|
+
return /*#__PURE__*/jsxRuntime.jsxs(reactNative.View, {
|
1858
|
+
style: styles$a.container,
|
1859
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(reactNative.Text, {
|
1860
|
+
style: styles$a.title,
|
1861
|
+
children: "Lista Drag\xE1vel (Esperando que a corre\xE7\xE3o final funcione \uD83D\uDE4F)"
|
1862
|
+
}), /*#__PURE__*/jsxRuntime.jsx(reactNative.View, {
|
1863
|
+
style: {
|
1864
|
+
height: items.length * ITEM_HEIGHT,
|
1865
|
+
width: '100%'
|
1861
1866
|
},
|
1862
|
-
|
1863
|
-
var
|
1864
|
-
|
1865
|
-
|
1866
|
-
|
1867
|
-
|
1868
|
-
|
1869
|
-
|
1870
|
-
|
1871
|
-
|
1872
|
-
|
1867
|
+
children: items.map(function (item) {
|
1868
|
+
var _panRespondersRef$cur, _panRespondersRef$cur2;
|
1869
|
+
var y = positions[item.value];
|
1870
|
+
if (!y) return null;
|
1871
|
+
var isDragging = draggingId === item.value;
|
1872
|
+
return /*#__PURE__*/jsxRuntime.jsxs(reactNative.Animated.View, _extends({}, (_panRespondersRef$cur = (_panRespondersRef$cur2 = panRespondersRef.current[item.value]) == null ? void 0 : _panRespondersRef$cur2.panHandlers) != null ? _panRespondersRef$cur : {}, {
|
1873
|
+
style: [styles$a.item, {
|
1874
|
+
position: 'absolute',
|
1875
|
+
left: 0,
|
1876
|
+
right: 0,
|
1877
|
+
height: ITEM_HEIGHT - 8,
|
1878
|
+
transform: [{
|
1879
|
+
translateY: y
|
1880
|
+
}],
|
1881
|
+
zIndex: isDragging ? 999 : 0,
|
1882
|
+
elevation: isDragging ? 999 : 0
|
1883
|
+
}],
|
1884
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(reactNative.View, {
|
1885
|
+
style: styles$a.handle,
|
1886
|
+
children: /*#__PURE__*/jsxRuntime.jsx(reactNative.Text, {
|
1887
|
+
style: styles$a.handleText,
|
1888
|
+
children: "\u2261"
|
1889
|
+
})
|
1890
|
+
}), /*#__PURE__*/jsxRuntime.jsx(reactNative.Text, {
|
1891
|
+
style: styles$a.itemText,
|
1892
|
+
children: item.label
|
1893
|
+
}), /*#__PURE__*/jsxRuntime.jsx(reactNative.TouchableOpacity, {
|
1894
|
+
onPress: function onPress() {
|
1895
|
+
return removeItem(item.value);
|
1896
|
+
},
|
1897
|
+
style: styles$a.del,
|
1898
|
+
children: /*#__PURE__*/jsxRuntime.jsx(reactNative.Text, {
|
1899
|
+
style: {
|
1900
|
+
color: '#fff'
|
1901
|
+
},
|
1902
|
+
children: "X"
|
1903
|
+
})
|
1904
|
+
})]
|
1905
|
+
}), item.value);
|
1906
|
+
})
|
1907
|
+
})]
|
1873
1908
|
});
|
1874
1909
|
}
|
1875
1910
|
var styles$a = /*#__PURE__*/reactNative.StyleSheet.create({
|
1876
|
-
|
1911
|
+
container: {
|
1912
|
+
flex: 1,
|
1913
|
+
paddingHorizontal: 20,
|
1914
|
+
backgroundColor: '#f5f7fb'
|
1915
|
+
},
|
1916
|
+
title: {
|
1917
|
+
fontSize: 18,
|
1918
|
+
fontWeight: '600',
|
1919
|
+
marginBottom: 12
|
1920
|
+
},
|
1921
|
+
item: {
|
1922
|
+
backgroundColor: '#fff',
|
1923
|
+
borderRadius: 10,
|
1924
|
+
marginVertical: 4,
|
1925
|
+
paddingHorizontal: 12,
|
1926
|
+
alignItems: 'center',
|
1877
1927
|
flexDirection: 'row',
|
1878
|
-
|
1879
|
-
|
1880
|
-
|
1881
|
-
|
1928
|
+
elevation: 3,
|
1929
|
+
shadowColor: '#000',
|
1930
|
+
shadowOpacity: 0.05,
|
1931
|
+
shadowRadius: 6
|
1882
1932
|
},
|
1883
|
-
|
1884
|
-
|
1933
|
+
handle: {
|
1934
|
+
width: 40,
|
1935
|
+
alignItems: 'center',
|
1936
|
+
justifyContent: 'center'
|
1937
|
+
},
|
1938
|
+
handleText: {
|
1939
|
+
fontSize: 22,
|
1940
|
+
color: '#666'
|
1941
|
+
},
|
1942
|
+
itemText: {
|
1943
|
+
fontSize: 16,
|
1944
|
+
flex: 1
|
1945
|
+
},
|
1946
|
+
del: {
|
1947
|
+
backgroundColor: '#e74c3c',
|
1948
|
+
height: 34,
|
1949
|
+
width: 34,
|
1950
|
+
borderRadius: 6,
|
1951
|
+
alignItems: 'center',
|
1952
|
+
justifyContent: 'center'
|
1885
1953
|
}
|
1886
1954
|
});
|
1887
1955
|
|