react-crud-mobile 1.0.72 → 1.0.73

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.
@@ -1,408 +1,408 @@
1
- import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
2
- import ElGrid from './grid/ElGrid';
3
- import ElCard from './card/ElCard';
4
- import UIChildren from './UIChildren';
5
- import ElTabs from './tabs/ElTabs';
6
- import ElLabel from './grid/ElLabel';
7
- import ElChart from './charts/ElChart';
8
- import UIComplete from './UIComplete';
9
- import ElRepeat from './grid/ElRepeat';
10
- import {
11
- Crud,
12
- HtmlUtils,
13
- ScopeUtils,
14
- Utils,
15
- ElementType,
16
- } from 'react-crud-utils';
17
- import Link from './core/Link';
18
- import Icon from './core/Icon';
19
- import Button from './core/Button';
20
- import Select from './core/Select';
21
- import Switch from './core/Switch';
22
- import Option from './core/Option';
23
- import Radio from './core/Radio';
24
- import Input from './core/Input';
25
- import { Image, Linking, StyleSheet, Text, View } from 'react-native';
26
-
27
- export default function UIElement(props: ElementType) {
28
- let [scope] = useState(ScopeUtils.create(props));
29
- let [index, setIndex] = useState(0);
30
- let [error, setError]: string | any = useState(null);
31
- let options: any = scope.getOptions();
32
- let crud: Crud = Utils.nvl(props.crud, scope.crud);
33
- let original = scope.original;
34
- let type = original.type;
35
- let ref = useRef(null);
36
-
37
- scope.update = () => {
38
- setIndex(++index);
39
- };
40
-
41
- let router: any = {
42
- list: ElGrid,
43
- grid: ElGrid,
44
- label: ElLabel,
45
- card: ElCard,
46
- repeat: ElRepeat,
47
- tabs: ElTabs,
48
- chart: ElChart,
49
- };
50
-
51
- let CurrentRouter = () => {
52
- if (router[type]) {
53
- let Aux = router[type];
54
-
55
- return <Aux crud={crud} {...props} scope={scope} />;
56
- }
57
- return <></>;
58
- };
59
-
60
- const Custom = () => {
61
- let c: any = original.custom;
62
-
63
- if (c) {
64
- if (typeof c === 'string') {
65
- return (
66
- <UIElement
67
- element={{ value: c, type: 'dummy' }}
68
- crud={crud}
69
- ></UIElement>
70
- );
71
- }
72
-
73
- return (
74
- <UIElement
75
- type={c.type}
76
- tag={c.type}
77
- {...c.props}
78
- crud={crud}
79
- ></UIElement>
80
- );
81
- }
82
-
83
- return <></>;
84
- };
85
-
86
- if (scope.is('type', 'dummy')) {
87
- return <>{scope.getDisplayValue()}</>;
88
- }
89
-
90
- let onCheck = () => {
91
- let v = scope.getValue();
92
- let check = !(v === true);
93
-
94
- onChange({ target: { value: check } });
95
- };
96
-
97
- let onChange = (e: any) => {
98
- let val = e.target.value;
99
-
100
- if (scope.isType('integer', 'int', 'number')) {
101
- val = parseInt(val);
102
- } else if (scope.isType('decimal')) {
103
- val = parseFloat(val);
104
- }
105
-
106
- if (scope.isType('select', 'complete')) {
107
- val = scope.getSelectedItem(val);
108
- }
109
-
110
- scope.changeValue(val);
111
- scope.update();
112
- };
113
-
114
- let onClick = (e: any) => {
115
- scope.call('click');
116
- };
117
-
118
- let defaultsInput: any = {
119
- label: scope.getLabel(),
120
- value: scope.getValue(),
121
- onChange: onChange,
122
- };
123
-
124
- if (scope.isType('password')) {
125
- defaultsInput.type = 'password';
126
- }
127
-
128
- const getStyle = (part?: string) => {
129
- let key = Utils.nvl(part, 'root');
130
- let def = styles[key];
131
-
132
- return { ...def, ...scope.getStyle(part) };
133
- };
134
-
135
- let elStyle = getStyle('element');
136
-
137
- let defaultsUI: any = {
138
- required: scope.isRequired(),
139
- size: 'small',
140
- scope,
141
- crud,
142
- style: elStyle,
143
- placeholder: scope.attr('placeholder', 'Digite aqui'),
144
- };
145
-
146
- let isChecked = () => {
147
- let v = scope.getValue();
148
-
149
- return v === true;
150
- };
151
-
152
- let hasChildren = () => {
153
- if (scope.isInput()) {
154
- return false;
155
- }
156
-
157
- return !Utils.isEmpty(props.children) || !Utils.isEmpty(props.elements);
158
- };
159
-
160
- if (!scope.isRendered() || scope.is('type', 'define')) {
161
- return <></>;
162
- }
163
-
164
- scope.error = (msg: string) => {
165
- error = msg;
166
- setError(msg);
167
- };
168
-
169
- useEffect(() => {
170
- if (!scope.ready) {
171
- scope.ready = true;
172
-
173
- scope.call('load');
174
-
175
- if (scope.isType('list', 'repeat')) {
176
- scope.search();
177
- } else if (original.list) {
178
- scope.call('list');
179
- }
180
- scope.start();
181
- }
182
- });
183
-
184
- const CustomIcon = () => {
185
- if (typeof original.icon === 'string') {
186
- return <Icon>{scope.getIcon()}</Icon>;
187
- }
188
- return <>{original.icon}</>;
189
- };
190
-
191
- const getLabelClass = (type: string) => {
192
- let clss = `ui-text ui-${type}-text`;
193
- let icon = scope.getIcon();
194
-
195
- if (icon) {
196
- clss = clss + ` ui-icon ui-${type}-icon`;
197
- }
198
- return clss;
199
- };
200
-
201
- let hasCustomRoute = () => {
202
- if (router[type]) return true;
203
- return false;
204
- };
205
-
206
- scope.open = (args: any) => {
207
- Linking.openURL(args.url);
208
- };
209
-
210
- if (scope.isType('dialog')) {
211
- let name = original.name;
212
-
213
- if (!crud.dialogs[name]) {
214
- let dlg: any = { config: { ...original } };
215
-
216
- dlg.component = (args: any) => {
217
- return <UIChildren {...props} scope={scope} crud={crud} />;
218
- };
219
-
220
- crud.dialogs[name] = dlg;
221
- }
222
- return <></>;
223
- }
224
-
225
- useLayoutEffect(() => {
226
- if (ref?.current && scope.is('type', 'card', 'list', 'tabs', 'stepper')) {
227
- let el: any = ref?.current;
228
-
229
- if (el) {
230
- let bg = HtmlUtils.getBGColor(el);
231
-
232
- if (bg === 'rgb(255, 255, 255)') {
233
- el.classList.add('ui-dark');
234
- } else {
235
- el.classList.add('ui-light');
236
- }
237
- }
238
- }
239
- });
240
-
241
- const isShowLabel = () => {
242
- if (typeof original.label !== 'undefined') {
243
- console.log(original.label);
244
- return true;
245
- }
246
-
247
- return false;
248
- };
249
-
250
- const isShowInner = () => {
251
- if (hasChildren() || hasCustomRoute()) {
252
- return false;
253
- }
254
- return true;
255
- };
256
-
257
- return (
258
- <>
259
- <View ref={ref} style={getStyle()}>
260
- <>
261
- {isShowLabel() && (
262
- <Text style={getStyle('label')}>{scope.getLabel()}</Text>
263
- )}
264
- {isShowInner() && (
265
- <>
266
- <View style={getStyle('inner')}>
267
- {scope.is('type', 'button') && (
268
- <Button
269
- {...defaultsUI}
270
- onClick={onClick}
271
- variant={scope.attr('variant', 'outlined')}
272
- >
273
- {original.icon && <CustomIcon />}
274
- {original.label && (
275
- <Text style={scope.getPart('label', 'button')}>
276
- {scope.getLabel()}
277
- </Text>
278
- )}
279
- </Button>
280
- )}
281
- {scope.is('type', 'icon') && (
282
- <Icon
283
- {...defaultsUI}
284
- onClick={onClick}
285
- variant={scope.attr('variant', 'outlined')}
286
- >
287
- {scope.getDisplayValue()}
288
- </Icon>
289
- )}
290
- {scope.is('type', 'link') && (
291
- <Link
292
- {...defaultsUI}
293
- onClick={onClick}
294
- variant={scope.attr('variant', 'outlined')}
295
- >
296
- {original.icon && <CustomIcon />}
297
- {original.label && (
298
- <Text style={scope.getPart('label', 'link')}>
299
- {scope.getLabel()}
300
- </Text>
301
- )}
302
- </Link>
303
- )}
304
- {scope.is(
305
- 'type',
306
- 'text',
307
- 'number',
308
- 'phone',
309
- 'postalCode',
310
- 'money',
311
- 'password',
312
- 'email'
313
- ) && (
314
- <Input
315
- {...defaultsInput}
316
- {...defaultsUI}
317
- InputProps={{ ...original.inputProps }}
318
- />
319
- )}
320
- {scope.is('type', 'complete', 'autocomplete') && (
321
- <UIComplete
322
- scope={scope}
323
- defaultsInput={defaultsInput}
324
- defaultsUI={defaultsUI}
325
- />
326
- )}
327
- {scope.is('type', 'checkbox', 'boolean', 'switch') && (
328
- <Switch
329
- checked={isChecked()}
330
- {...defaultsInput}
331
- onChange={onCheck}
332
- />
333
- )}
334
- {scope.is('type', 'select') && (
335
- <Select
336
- {...defaultsInput}
337
- {...defaultsUI}
338
- value={scope.getSelectedValue()}
339
- >
340
- <Option value={''}>Selecione</Option>
341
- {options.map((row: any, i: number) => (
342
- <Option key={'i' + i} value={row.value}>
343
- {row.label}
344
- </Option>
345
- ))}
346
- </Select>
347
- )}
348
- {scope.is('type', 'radio') && (
349
- <Radio {...defaultsInput} {...defaultsUI} row>
350
- {options.map((row: any, i: number) => (
351
- <Option
352
- key={'i' + i}
353
- control={<Radio {...defaultsUI} />}
354
- label={row.label}
355
- value={row.value}
356
- />
357
- ))}
358
- </Radio>
359
- )}
360
- {scope.is('type', 'custom') && <Custom />}
361
- {scope.is('type', 'column') && (
362
- <>
363
- {scope.is('format', 'img') && (
364
- <Image source={scope.getDisplayValue()} />
365
- )}
366
- {scope.is('format', 'icon') && (
367
- <Icon className={scope.getDisplayValue()} />
368
- )}
369
- {!scope.is('format', 'icon', 'img') && (
370
- <Text>{scope.getDisplayValue()}</Text>
371
- )}
372
- </>
373
- )}
374
- {scope.is('type', 'output') && (
375
- <Text>{scope.getDisplayValue()}</Text>
376
- )}
377
- </View>
378
- {error && <View style={getStyle('error')}>{error}</View>}
379
- </>
380
- )}
381
- <CurrentRouter />
382
- {!scope.is(
383
- 'type',
384
- 'card',
385
- 'tabs',
386
- 'grid',
387
- 'list',
388
- 'define',
389
- 'repeat'
390
- ) && <UIChildren {...props} scope={scope} crud={crud} />}
391
- </>
392
- </View>
393
- </>
394
- );
395
- }
396
-
397
- const styles = StyleSheet.create({
398
- root: {
399
- flex: 1,
400
- gap: 10,
401
- flexDirection: 'column',
402
- flexWrap: 'wrap',
403
- width: '100%',
404
- alignItems: 'flex-start',
405
- },
406
- label: { width: '100%', fontWeight: 600 },
407
- inner: { width: '100%' },
408
- });
1
+ import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
2
+ import ElGrid from './grid/ElGrid';
3
+ import ElCard from './card/ElCard';
4
+ import UIChildren from './UIChildren';
5
+ import ElTabs from './tabs/ElTabs';
6
+ import ElLabel from './grid/ElLabel';
7
+ import ElChart from './charts/ElChart';
8
+ import UIComplete from './UIComplete';
9
+ import ElRepeat from './grid/ElRepeat';
10
+ import {
11
+ Crud,
12
+ HtmlUtils,
13
+ ScopeUtils,
14
+ Utils,
15
+ ElementType,
16
+ } from 'react-crud-utils';
17
+ import Link from './core/Link';
18
+ import Icon from './core/Icon';
19
+ import Button from './core/Button';
20
+ import Select from './core/Select';
21
+ import Switch from './core/Switch';
22
+ import Option from './core/Option';
23
+ import Radio from './core/Radio';
24
+ import Input from './core/Input';
25
+ import { Image, Linking, StyleSheet, Text, View } from 'react-native';
26
+
27
+ export default function UIElement(props: ElementType) {
28
+ let [scope] = useState(ScopeUtils.create(props));
29
+ let [index, setIndex] = useState(0);
30
+ let [error, setError]: string | any = useState(null);
31
+ let options: any = scope.getOptions();
32
+ let crud: Crud = Utils.nvl(props.crud, scope.crud);
33
+ let original = scope.original;
34
+ let type = original.type;
35
+ let ref = useRef(null);
36
+
37
+ scope.update = () => {
38
+ setIndex(++index);
39
+ };
40
+
41
+ let router: any = {
42
+ list: ElGrid,
43
+ grid: ElGrid,
44
+ label: ElLabel,
45
+ card: ElCard,
46
+ repeat: ElRepeat,
47
+ tabs: ElTabs,
48
+ chart: ElChart,
49
+ };
50
+
51
+ let CurrentRouter = () => {
52
+ if (router[type]) {
53
+ let Aux = router[type];
54
+
55
+ return <Aux crud={crud} {...props} scope={scope} />;
56
+ }
57
+ return <></>;
58
+ };
59
+
60
+ const Custom = () => {
61
+ let c: any = original.custom;
62
+
63
+ if (c) {
64
+ if (typeof c === 'string') {
65
+ return (
66
+ <UIElement
67
+ element={{ value: c, type: 'dummy' }}
68
+ crud={crud}
69
+ ></UIElement>
70
+ );
71
+ }
72
+
73
+ return (
74
+ <UIElement
75
+ type={c.type}
76
+ tag={c.type}
77
+ {...c.props}
78
+ crud={crud}
79
+ ></UIElement>
80
+ );
81
+ }
82
+
83
+ return <></>;
84
+ };
85
+
86
+ if (scope.is('type', 'dummy')) {
87
+ return <>{scope.getDisplayValue()}</>;
88
+ }
89
+
90
+ let onCheck = () => {
91
+ let v = scope.getValue();
92
+ let check = !(v === true);
93
+
94
+ onChange({ target: { value: check } });
95
+ };
96
+
97
+ let onChange = (e: any) => {
98
+ let val = e.target.value;
99
+
100
+ if (scope.isType('integer', 'int', 'number')) {
101
+ val = parseInt(val);
102
+ } else if (scope.isType('decimal')) {
103
+ val = parseFloat(val);
104
+ }
105
+
106
+ if (scope.isType('select', 'complete')) {
107
+ val = scope.getSelectedItem(val);
108
+ }
109
+
110
+ scope.changeValue(val);
111
+ scope.update();
112
+ };
113
+
114
+ let onClick = (e: any) => {
115
+ scope.call('click');
116
+ };
117
+
118
+ let defaultsInput: any = {
119
+ label: scope.getLabel(),
120
+ value: scope.getValue(),
121
+ onChange: onChange,
122
+ };
123
+
124
+ if (scope.isType('password')) {
125
+ defaultsInput.type = 'password';
126
+ }
127
+
128
+ const getStyle = (part?: string) => {
129
+ let key = Utils.nvl(part, 'root');
130
+ let def = styles[key];
131
+
132
+ return { ...def, ...scope.getStyle(part) };
133
+ };
134
+
135
+ let elStyle = getStyle('element');
136
+
137
+ let defaultsUI: any = {
138
+ required: scope.isRequired(),
139
+ size: 'small',
140
+ scope,
141
+ crud,
142
+ style: elStyle,
143
+ placeholder: scope.attr('placeholder', 'Digite aqui'),
144
+ };
145
+
146
+ let isChecked = () => {
147
+ let v = scope.getValue();
148
+
149
+ return v === true;
150
+ };
151
+
152
+ let hasChildren = () => {
153
+ if (scope.isInput()) {
154
+ return false;
155
+ }
156
+
157
+ return !Utils.isEmpty(props.children) || !Utils.isEmpty(props.elements);
158
+ };
159
+
160
+ if (!scope.isRendered() || scope.is('type', 'define')) {
161
+ return <></>;
162
+ }
163
+
164
+ scope.error = (msg: string) => {
165
+ error = msg;
166
+ setError(msg);
167
+ };
168
+
169
+ useEffect(() => {
170
+ if (!scope.ready) {
171
+ scope.ready = true;
172
+
173
+ scope.call('load');
174
+
175
+ if (scope.isType('list', 'repeat')) {
176
+ scope.search();
177
+ } else if (original.list) {
178
+ scope.call('list');
179
+ }
180
+ scope.start();
181
+ }
182
+ });
183
+
184
+ const CustomIcon = () => {
185
+ if (typeof original.icon === 'string') {
186
+ return <Icon>{scope.getIcon()}</Icon>;
187
+ }
188
+ return <>{original.icon}</>;
189
+ };
190
+
191
+ const getLabelClass = (type: string) => {
192
+ let clss = `ui-text ui-${type}-text`;
193
+ let icon = scope.getIcon();
194
+
195
+ if (icon) {
196
+ clss = clss + ` ui-icon ui-${type}-icon`;
197
+ }
198
+ return clss;
199
+ };
200
+
201
+ let hasCustomRoute = () => {
202
+ if (router[type]) return true;
203
+ return false;
204
+ };
205
+
206
+ scope.open = (args: any) => {
207
+ Linking.openURL(args.url);
208
+ };
209
+
210
+ if (scope.isType('dialog')) {
211
+ let name = original.name;
212
+
213
+ if (!crud.dialogs[name]) {
214
+ let dlg: any = { config: { ...original } };
215
+
216
+ dlg.component = (args: any) => {
217
+ return <UIChildren {...props} scope={scope} crud={crud} />;
218
+ };
219
+
220
+ crud.dialogs[name] = dlg;
221
+ }
222
+ return <></>;
223
+ }
224
+
225
+ useLayoutEffect(() => {
226
+ if (ref?.current && scope.is('type', 'card', 'list', 'tabs', 'stepper')) {
227
+ let el: any = ref?.current;
228
+
229
+ if (el) {
230
+ let bg = HtmlUtils.getBGColor(el);
231
+
232
+ if (bg === 'rgb(255, 255, 255)') {
233
+ el.classList.add('ui-dark');
234
+ } else {
235
+ el.classList.add('ui-light');
236
+ }
237
+ }
238
+ }
239
+ });
240
+
241
+ const isShowLabel = () => {
242
+ if (typeof original.label !== 'undefined') {
243
+ console.log(original.label);
244
+ return true;
245
+ }
246
+
247
+ return false;
248
+ };
249
+
250
+ const isShowInner = () => {
251
+ if (hasChildren() || hasCustomRoute()) {
252
+ return false;
253
+ }
254
+ return true;
255
+ };
256
+
257
+ return (
258
+ <>
259
+ <View ref={ref} style={getStyle()}>
260
+ <>
261
+ {isShowLabel() && (
262
+ <Text style={getStyle('label')}>{scope.getLabel()}</Text>
263
+ )}
264
+ {isShowInner() && (
265
+ <>
266
+ <View style={getStyle('inner')}>
267
+ {scope.is('type', 'button') && (
268
+ <Button
269
+ {...defaultsUI}
270
+ onClick={onClick}
271
+ variant={scope.attr('variant', 'outlined')}
272
+ >
273
+ {original.icon && <CustomIcon />}
274
+ {original.label && (
275
+ <Text style={scope.getPart('label', 'button')}>
276
+ {scope.getLabel()}
277
+ </Text>
278
+ )}
279
+ </Button>
280
+ )}
281
+ {scope.is('type', 'icon') && (
282
+ <Icon
283
+ {...defaultsUI}
284
+ onClick={onClick}
285
+ variant={scope.attr('variant', 'outlined')}
286
+ >
287
+ {scope.getDisplayValue()}
288
+ </Icon>
289
+ )}
290
+ {scope.is('type', 'link') && (
291
+ <Link
292
+ {...defaultsUI}
293
+ onClick={onClick}
294
+ variant={scope.attr('variant', 'outlined')}
295
+ >
296
+ {original.icon && <CustomIcon />}
297
+ {original.label && (
298
+ <Text style={scope.getPart('label', 'link')}>
299
+ {scope.getLabel()}
300
+ </Text>
301
+ )}
302
+ </Link>
303
+ )}
304
+ {scope.is(
305
+ 'type',
306
+ 'text',
307
+ 'number',
308
+ 'phone',
309
+ 'postalCode',
310
+ 'money',
311
+ 'password',
312
+ 'email'
313
+ ) && (
314
+ <Input
315
+ {...defaultsInput}
316
+ {...defaultsUI}
317
+ InputProps={{ ...original.inputProps }}
318
+ />
319
+ )}
320
+ {scope.is('type', 'complete', 'autocomplete') && (
321
+ <UIComplete
322
+ scope={scope}
323
+ defaultsInput={defaultsInput}
324
+ defaultsUI={defaultsUI}
325
+ />
326
+ )}
327
+ {scope.is('type', 'checkbox', 'boolean', 'switch') && (
328
+ <Switch
329
+ checked={isChecked()}
330
+ {...defaultsInput}
331
+ onChange={onCheck}
332
+ />
333
+ )}
334
+ {scope.is('type', 'select') && (
335
+ <Select
336
+ {...defaultsInput}
337
+ {...defaultsUI}
338
+ value={scope.getSelectedValue()}
339
+ >
340
+ <Option value={''}>Selecione</Option>
341
+ {options.map((row: any, i: number) => (
342
+ <Option key={'i' + i} value={row.value}>
343
+ {row.label}
344
+ </Option>
345
+ ))}
346
+ </Select>
347
+ )}
348
+ {scope.is('type', 'radio') && (
349
+ <Radio {...defaultsInput} {...defaultsUI} row>
350
+ {options.map((row: any, i: number) => (
351
+ <Option
352
+ key={'i' + i}
353
+ control={<Radio {...defaultsUI} />}
354
+ label={row.label}
355
+ value={row.value}
356
+ />
357
+ ))}
358
+ </Radio>
359
+ )}
360
+ {scope.is('type', 'custom') && <Custom />}
361
+ {scope.is('type', 'column') && (
362
+ <>
363
+ {scope.is('format', 'img') && (
364
+ <Image source={scope.getDisplayValue()} />
365
+ )}
366
+ {scope.is('format', 'icon') && (
367
+ <Icon className={scope.getDisplayValue()} />
368
+ )}
369
+ {!scope.is('format', 'icon', 'img') && (
370
+ <Text>{scope.getDisplayValue()}</Text>
371
+ )}
372
+ </>
373
+ )}
374
+ {scope.is('type', 'output') && (
375
+ <Text>{scope.getDisplayValue()}</Text>
376
+ )}
377
+ </View>
378
+ {error && <View style={getStyle('error')}>{error}</View>}
379
+ </>
380
+ )}
381
+ <CurrentRouter />
382
+ {!scope.is(
383
+ 'type',
384
+ 'card',
385
+ 'tabs',
386
+ 'grid',
387
+ 'list',
388
+ 'define',
389
+ 'repeat'
390
+ ) && <UIChildren {...props} scope={scope} crud={crud} />}
391
+ </>
392
+ </View>
393
+ </>
394
+ );
395
+ }
396
+
397
+ const styles = StyleSheet.create({
398
+ root: {
399
+ flex: 1,
400
+ gap: 10,
401
+ flexDirection: 'column',
402
+ flexWrap: 'wrap',
403
+ width: '100%',
404
+ alignItems: 'flex-start',
405
+ },
406
+ label: { width: '100%', fontWeight: 600 },
407
+ inner: { width: '100%' },
408
+ });