react-crud-mobile 1.3.51 → 1.3.53
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/UI.d.ts +1 -0
- package/dist/elements/core/UIOrder.d.ts +3 -0
- package/dist/react-crud-mobile.cjs.development.js +158 -2
- 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 +158 -2
- package/dist/react-crud-mobile.esm.js.map +1 -1
- package/package.json +3 -2
- package/src/elements/UI.tsx +1 -0
- package/src/elements/UIElement.tsx +6 -0
- package/src/elements/core/UIOrder.tsx +169 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.3.
|
|
2
|
+
"version": "1.3.53",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"description": "Uma biblioteca de componentes para React Native",
|
|
5
5
|
"main": "dist/index.js",
|
|
@@ -45,9 +45,10 @@
|
|
|
45
45
|
"@react-native-vector-icons/ionicons": "^7.4.0",
|
|
46
46
|
"@react-native-vector-icons/material-icons": "^0.0.1",
|
|
47
47
|
"react": "19.0.0",
|
|
48
|
-
"react-crud-utils": "^0.1.
|
|
48
|
+
"react-crud-utils": "^0.1.368",
|
|
49
49
|
"react-dom": "19.0.0",
|
|
50
50
|
"react-native": "0.79.2",
|
|
51
|
+
"react-native-draggable-flatlist": "^4.0.3",
|
|
51
52
|
"react-native-gesture-handler": "~2.24.0",
|
|
52
53
|
"react-native-reanimated": "~3.17.4",
|
|
53
54
|
"react-native-safe-area-context": "5.4.0",
|
package/src/elements/UI.tsx
CHANGED
|
@@ -18,6 +18,7 @@ import UIInclude from './core/UIInclude';
|
|
|
18
18
|
import SafeView from './core/SafeView';
|
|
19
19
|
|
|
20
20
|
const UI = {
|
|
21
|
+
Order: (props: ListType) => <UIElement {...props} type="order" />,
|
|
21
22
|
List: (props: ListType) => <UIElement {...props} type="list" />,
|
|
22
23
|
Row: (props: UserType) => <UIElement {...props} type="row" />,
|
|
23
24
|
Value: (props: UserType) => <UIElement {...props} type="value" />,
|
|
@@ -45,6 +45,7 @@ import UIModal from './core/UIModal';
|
|
|
45
45
|
import { Ionicons } from '@expo/vector-icons';
|
|
46
46
|
import UIView from './core/UIView';
|
|
47
47
|
import Toast from 'react-native-toast-message';
|
|
48
|
+
import UIOrder from './core/UIOrder';
|
|
48
49
|
|
|
49
50
|
const CrudContext = createContext<any>({});
|
|
50
51
|
|
|
@@ -508,6 +509,11 @@ export default function UIElement(props: ElementType) {
|
|
|
508
509
|
{scope.isType('list', 'repeat') && (
|
|
509
510
|
<UIList {...props} scope={scope} crud={crud} />
|
|
510
511
|
)}
|
|
512
|
+
|
|
513
|
+
{scope.isType('order') && (
|
|
514
|
+
<UIOrder {...props} scope={scope} crud={crud} />
|
|
515
|
+
)}
|
|
516
|
+
|
|
511
517
|
{scope.isType('dialog') && (
|
|
512
518
|
<UIModal {...props} scope={scope} crud={crud} />
|
|
513
519
|
)}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { ChildType, ComponentUtils, ScopeUtils, Utils } from 'react-crud-utils';
|
|
3
|
+
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
|
|
4
|
+
import UI from '../UI';
|
|
5
|
+
import { Ionicons } from '@expo/vector-icons';
|
|
6
|
+
import DraggableFlatList from 'react-native-draggable-flatlist';
|
|
7
|
+
|
|
8
|
+
export default function UIOrder(props: ChildType) {
|
|
9
|
+
const scope = props.scope;
|
|
10
|
+
const crud = scope.crud;
|
|
11
|
+
const original = scope.original;
|
|
12
|
+
const cols = Utils.nvl(scope.getPart('cols', undefined, 1));
|
|
13
|
+
const add = ComponentUtils.getDefine(props, 'add');
|
|
14
|
+
const hideAddWhenEmpty = original.hideAddWhenEmpty;
|
|
15
|
+
|
|
16
|
+
const getStyle = (key: string, extra?: any) => {
|
|
17
|
+
return scope.getStyle(key, { ...extra, ...styles[key] });
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const getContainerStyle = (extra?: any) => {
|
|
21
|
+
let row = getStyle('container', {});
|
|
22
|
+
|
|
23
|
+
if (cols > 1) {
|
|
24
|
+
row = { ...row, flexDirection: 'row', flexWrap: 'wrap' };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return row;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const LocalData = () => {
|
|
31
|
+
let [index, setIndex] = useState(scope.updateIndex);
|
|
32
|
+
|
|
33
|
+
scope.update = () => {
|
|
34
|
+
scope.updateIndex = ++index;
|
|
35
|
+
|
|
36
|
+
setIndex(index);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
let keyData = scope.key('data');
|
|
40
|
+
|
|
41
|
+
const items = Utils.call(() => {
|
|
42
|
+
let list = Utils.nvl(scope.getItems(), []);
|
|
43
|
+
|
|
44
|
+
if (original.search && !original.list?.url) {
|
|
45
|
+
let query = crud
|
|
46
|
+
.get('query', '')
|
|
47
|
+
.toLowerCase()
|
|
48
|
+
.trim() as string;
|
|
49
|
+
|
|
50
|
+
if (query.length > 1) {
|
|
51
|
+
let filters: any[] = [];
|
|
52
|
+
let filterBy = Utils.nvl(original.filterBy, 'label');
|
|
53
|
+
|
|
54
|
+
Utils.each(list, o => {
|
|
55
|
+
let label = o[filterBy];
|
|
56
|
+
|
|
57
|
+
if (label) {
|
|
58
|
+
if (label.includes(query)) {
|
|
59
|
+
filters.push(o);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return filters;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return list;
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const isShowAdd = () => {
|
|
71
|
+
if (!Utils.isEmpty(items)) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
return hideAddWhenEmpty !== true;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
let Empty = () => {
|
|
78
|
+
if (!Utils.isEmpty(items)) {
|
|
79
|
+
return <></>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let empty = scope.attr('empty', 'Sem registro');
|
|
83
|
+
|
|
84
|
+
if (!empty) {
|
|
85
|
+
return <></>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (typeof empty === 'string') {
|
|
89
|
+
return (
|
|
90
|
+
<Text
|
|
91
|
+
style={scope.getStyle('empty', {
|
|
92
|
+
flex: 1,
|
|
93
|
+
fontWeight: 500,
|
|
94
|
+
fontSize: 20,
|
|
95
|
+
padding: 10,
|
|
96
|
+
textAlign: 'center',
|
|
97
|
+
justifyContent: 'center',
|
|
98
|
+
alignItems: 'center',
|
|
99
|
+
})}
|
|
100
|
+
>
|
|
101
|
+
{empty}
|
|
102
|
+
</Text>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return <>{empty}</>;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const renderItem = ({ item, drag, isActive }) => {
|
|
110
|
+
return (
|
|
111
|
+
<TouchableOpacity
|
|
112
|
+
style={[
|
|
113
|
+
styles.row,
|
|
114
|
+
{ backgroundColor: isActive ? 'lightblue' : 'white' },
|
|
115
|
+
]}
|
|
116
|
+
onLongPress={drag} // Initiate drag on long press
|
|
117
|
+
>
|
|
118
|
+
<Text style={styles.text}>{scope.getItemLabel(item)}</Text>
|
|
119
|
+
</TouchableOpacity>
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<View key={keyData} style={getContainerStyle()}>
|
|
125
|
+
<Empty />
|
|
126
|
+
<DraggableFlatList
|
|
127
|
+
data={items}
|
|
128
|
+
renderItem={renderItem}
|
|
129
|
+
keyExtractor={item => scope.getItemValue(item)}
|
|
130
|
+
onDragEnd={({ data }) => {
|
|
131
|
+
scope.changeValue(data);
|
|
132
|
+
}}
|
|
133
|
+
/>
|
|
134
|
+
{isShowAdd() && <>{add}</>}
|
|
135
|
+
</View>
|
|
136
|
+
);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
<>
|
|
141
|
+
{original.search !== false && (
|
|
142
|
+
<UI.Text
|
|
143
|
+
placeholder="Pesquisar..."
|
|
144
|
+
field="query"
|
|
145
|
+
crud={crud}
|
|
146
|
+
style={{ marginBottom: 10 }}
|
|
147
|
+
change={{
|
|
148
|
+
action: () => {
|
|
149
|
+
scope.search();
|
|
150
|
+
},
|
|
151
|
+
}}
|
|
152
|
+
icon={<Ionicons name="search" size={20} color="#888" />}
|
|
153
|
+
/>
|
|
154
|
+
)}
|
|
155
|
+
<LocalData />
|
|
156
|
+
</>
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const styles = StyleSheet.create({
|
|
161
|
+
row: {
|
|
162
|
+
padding: 20,
|
|
163
|
+
borderBottomWidth: 1,
|
|
164
|
+
borderBottomColor: '#ccc',
|
|
165
|
+
},
|
|
166
|
+
text: {
|
|
167
|
+
fontSize: 18,
|
|
168
|
+
},
|
|
169
|
+
});
|