@chem-po/react-native 0.0.52 → 0.0.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.
Files changed (98) hide show
  1. package/package.json +5 -20
  2. package/src/components/box/Center.tsx +0 -19
  3. package/src/components/box/CollapseHorizontal.tsx +0 -44
  4. package/src/components/box/ContentBox.tsx +0 -24
  5. package/src/components/box/DropShadow.tsx +0 -28
  6. package/src/components/box/ExpandOnMount.tsx +0 -74
  7. package/src/components/box/Expandable.tsx +0 -143
  8. package/src/components/box/FullSizeContainer.tsx +0 -64
  9. package/src/components/box/index.ts +0 -7
  10. package/src/components/button/ActionButton.tsx +0 -196
  11. package/src/components/button/ButtonText.tsx +0 -60
  12. package/src/components/button/DeleteButton.tsx +0 -288
  13. package/src/components/button/LoadingButton.tsx +0 -41
  14. package/src/components/button/Toggle.tsx +0 -109
  15. package/src/components/button/hooks.ts +0 -66
  16. package/src/components/button/index.ts +0 -5
  17. package/src/components/feed/FeedContentPane.tsx +0 -97
  18. package/src/components/feed/MediaFeed.tsx +0 -199
  19. package/src/components/feed/MediaFeedBackground.tsx +0 -136
  20. package/src/components/feed/MediaFeedRefresh.tsx +0 -113
  21. package/src/components/feed/constants.ts +0 -2
  22. package/src/components/feed/context.tsx +0 -19
  23. package/src/components/feed/hooks.ts +0 -279
  24. package/src/components/feed/index.ts +0 -2
  25. package/src/components/form/Condition.tsx +0 -27
  26. package/src/components/form/Field.tsx +0 -44
  27. package/src/components/form/Form.tsx +0 -452
  28. package/src/components/form/FormFooter.tsx +0 -164
  29. package/src/components/form/UploadProgress/index.tsx +0 -50
  30. package/src/components/form/index.ts +0 -3
  31. package/src/components/form/input/Editable.tsx +0 -206
  32. package/src/components/form/input/InputSlider.tsx +0 -71
  33. package/src/components/form/input/OptionalTag.tsx +0 -43
  34. package/src/components/form/input/StandaloneInput.tsx +0 -49
  35. package/src/components/form/input/boolean/index.tsx +0 -53
  36. package/src/components/form/input/color/index.tsx +0 -145
  37. package/src/components/form/input/common/InputClearButton.tsx +0 -57
  38. package/src/components/form/input/date/index.tsx +0 -125
  39. package/src/components/form/input/datetime/index.tsx +0 -176
  40. package/src/components/form/input/file/index.tsx +0 -310
  41. package/src/components/form/input/hooks/index.ts +0 -2
  42. package/src/components/form/input/hooks/useInputColor.ts +0 -7
  43. package/src/components/form/input/hooks/useInputImperativeHandle.ts +0 -22
  44. package/src/components/form/input/hooks/useInputStyles.ts +0 -114
  45. package/src/components/form/input/index.ts +0 -4
  46. package/src/components/form/input/input.tsx +0 -218
  47. package/src/components/form/input/multipleSelect/index.tsx +0 -221
  48. package/src/components/form/input/number/index.tsx +0 -108
  49. package/src/components/form/input/select/index.tsx +0 -152
  50. package/src/components/form/input/socialMedia/index.tsx +0 -235
  51. package/src/components/form/input/text/AutoResizeTextarea.tsx +0 -41
  52. package/src/components/form/input/text/index.tsx +0 -99
  53. package/src/components/form/input/text/textarea.tsx +0 -32
  54. package/src/components/form/input/text/useWebAutoResize.tsx +0 -73
  55. package/src/components/form/input/time/index.tsx +0 -125
  56. package/src/components/form/types.ts +0 -8
  57. package/src/components/form/view/file.tsx +0 -80
  58. package/src/components/form/view/index.tsx +0 -125
  59. package/src/components/form/view/multipleSelect.tsx +0 -85
  60. package/src/components/form/view/select.tsx +0 -83
  61. package/src/components/form/view/styles.ts +0 -12
  62. package/src/components/icons/index.tsx +0 -28
  63. package/src/components/image/ImageViewModal.tsx +0 -319
  64. package/src/components/image/index.ts +0 -1
  65. package/src/components/index.ts +0 -8
  66. package/src/components/layout/CollapseHorizontal.tsx +0 -92
  67. package/src/components/loading/CircularProgress.tsx +0 -56
  68. package/src/components/loading/Loading.tsx +0 -146
  69. package/src/components/loading/LoadingImage.tsx +0 -163
  70. package/src/components/loading/LoadingOverlay.tsx +0 -74
  71. package/src/components/loading/LoadingSwitch.tsx +0 -110
  72. package/src/components/loading/ProgressBar.tsx +0 -75
  73. package/src/components/loading/index.ts +0 -6
  74. package/src/components/text/AnimatedText.tsx +0 -68
  75. package/src/components/text/Txt.tsx +0 -12
  76. package/src/components/text/index.ts +0 -1
  77. package/src/components/theme/colorMode/DarkModeToggle.tsx +0 -47
  78. package/src/components/theme/colorMode/index.ts +0 -1
  79. package/src/components/theme/index.ts +0 -1
  80. package/src/constants/index.ts +0 -1
  81. package/src/constants/toast.ts +0 -24
  82. package/src/contexts/fonts.tsx +0 -23
  83. package/src/contexts/index.ts +0 -1
  84. package/src/contexts/root.tsx +0 -190
  85. package/src/hooks/index.ts +0 -3
  86. package/src/hooks/useFadeIn.ts +0 -48
  87. package/src/hooks/useFont.ts +0 -25
  88. package/src/hooks/useRefreshFontScale.ts +0 -39
  89. package/src/hooks/useThemeState.ts +0 -43
  90. package/src/index.ts +0 -6
  91. package/src/store/index.ts +0 -2
  92. package/src/store/useFontScale.ts +0 -8
  93. package/src/store/useScreen.ts +0 -25
  94. package/src/styles/fill.ts +0 -19
  95. package/src/types/forms.ts +0 -14
  96. package/src/types/index.ts +0 -1
  97. package/src/utils/downloadFile.ts +0 -61
  98. package/src/utils/downloadFileLegacy.ts +0 -66
@@ -1,279 +0,0 @@
1
- import { FetchFeedFunction } from '@chem-po/core'
2
- import { UpdatePanelsArgs, useAuth, useToast } from '@chem-po/react'
3
- import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
4
-
5
- const DEFAULT_LIMIT = 10
6
- export const useMediaFeed = (
7
- fetch: FetchFeedFunction,
8
- onUpdatePanels: (items: UpdatePanelsArgs) => void,
9
- limit: number = DEFAULT_LIMIT,
10
- authRequired = false,
11
- ) => {
12
- // first element is prev ids, second element is curr ids, third element is next ids
13
- const [ids, setIds] = useState<[string[] | null, string[] | null, string[] | null]>([
14
- null,
15
- null,
16
- null,
17
- ])
18
- const [idIdx, setIdIdx] = useState<number>(0)
19
- const user = useAuth(s => s.user)
20
-
21
- const [loading, setLoading] = useState(false)
22
- const [refreshing, setRefreshing] = useState(false)
23
- const [error, setError] = useState<string | null>(null)
24
- const [itemLoading, setItemLoading] = useState(false)
25
- const [direction, setDirection] = useState<'next' | 'prev' | null>(null)
26
-
27
- const fetchingId = useRef<string | null>(null)
28
-
29
- const idsRef = useRef<{ prev: string | null; curr: string | null; next: string | null }>({
30
- prev: null,
31
- curr: null,
32
- next: null,
33
- })
34
-
35
- const { showInfo, showError } = useToast()
36
-
37
- const updateCurr = useCallback(
38
- (id: string | null) => {
39
- if (id) {
40
- if (idsRef.current.prev === id) {
41
- idsRef.current.prev = null
42
- }
43
- if (idsRef.current.next === id) {
44
- idsRef.current.next = null
45
- }
46
- }
47
- idsRef.current.curr = id
48
- onUpdatePanels({ ...idsRef.current })
49
- },
50
- [onUpdatePanels],
51
- )
52
-
53
- const updateNext = useCallback(
54
- (id: string | null) => {
55
- if (id) {
56
- if (idsRef.current.prev === id) {
57
- idsRef.current.prev = null
58
- }
59
- if (idsRef.current.curr === id) {
60
- idsRef.current.curr = null
61
- }
62
- }
63
- idsRef.current.next = id
64
- onUpdatePanels({ ...idsRef.current })
65
- },
66
- [onUpdatePanels],
67
- )
68
-
69
- const updatePrev = useCallback(
70
- (id: string | null) => {
71
- if (id) {
72
- if (idsRef.current.curr === id) {
73
- idsRef.current.curr = null
74
- }
75
- if (idsRef.current.next === id) {
76
- idsRef.current.next = null
77
- }
78
- }
79
- idsRef.current.prev = id
80
- onUpdatePanels({ ...idsRef.current })
81
- },
82
- [onUpdatePanels],
83
- )
84
-
85
- const fetchIds = useCallback(
86
- async (
87
- startBefore: string | null,
88
- startAfter: string | null,
89
- isPrefetch: boolean,
90
- ): Promise<string[]> => {
91
- if (!user && authRequired) return []
92
- if (!isPrefetch) setLoading(true)
93
-
94
- try {
95
- const data = await fetch({ limit, startAfter, startBefore })
96
- if (!isPrefetch) {
97
- const firstId = data.ids[0]
98
- const secondId = data.ids[1] || null
99
- updateCurr(firstId)
100
- updateNext(secondId)
101
- updatePrev(startAfter)
102
- if (startAfter) {
103
- setIds(s => [s[1], data.ids, null])
104
- } else if (startBefore) {
105
- setIds(s => [null, data.ids, s[1]])
106
- } else {
107
- setIds([null, data.ids, null])
108
- }
109
- const newLastId = data.ids[data.ids.length - 1]
110
- if (newLastId) {
111
- fetchIds(null, newLastId, true)
112
- }
113
- } else if (startAfter) {
114
- setIds(s => [s[0], s[1], data.ids])
115
- } else if (startBefore) {
116
- setIds(s => [data.ids, s[1], s[2]])
117
- }
118
- setLoading(false)
119
- return data.ids || []
120
- } catch (err: any) {
121
- setError(err.message)
122
- // toast({
123
- // title: 'Error fetching feed',
124
- // description: err.message,
125
- // status: 'error',
126
- // duration: 9000,
127
- // isClosable: true,
128
- // })
129
- showError('Error fetching feed')
130
- }
131
- setLoading(false)
132
- return []
133
- },
134
- [fetch, user, authRequired, updateCurr, updateNext, updatePrev, limit, showError],
135
- )
136
-
137
- // handles prefetching of next items
138
- const getNextId = useCallback(
139
- async (currIdx: number, isPrefetch: boolean): Promise<{ id: string; idx: number } | null> => {
140
- const currIds = ids[1] ?? []
141
- const nextIds = ids[2] ?? []
142
- const nextIdx = currIdx + 1
143
- if (nextIdx < currIds.length) {
144
- return { id: currIds[nextIdx], idx: nextIdx }
145
- }
146
- if (nextIds[0]) {
147
- const newLastId = nextIds[nextIds.length - 1]
148
- if (!isPrefetch) {
149
- setIds(s => [s[1], s[2], null])
150
- fetchIds(null, newLastId, true)
151
- }
152
- return { id: nextIds[0], idx: 0 }
153
- }
154
- const fetchedNextIds = await fetchIds(null, currIds[currIds.length - 1], isPrefetch)
155
- const fetchedNextId = fetchedNextIds[0]
156
- return fetchedNextId ? { id: fetchedNextId, idx: 0 } : null
157
- },
158
- [ids, fetchIds],
159
- )
160
-
161
- const getPrevId = useCallback(
162
- async (currIdx: number, isPrefetch: boolean): Promise<{ id: string; idx: number } | null> => {
163
- const currIds = ids[1] ?? []
164
- const prevIds = ids[0] ?? []
165
- const prevIdx = currIdx - 1
166
- if (prevIdx >= 0) {
167
- return { id: currIds[prevIdx], idx: prevIdx }
168
- }
169
- if (prevIds[prevIds.length - 1]) {
170
- const newFirstId = prevIds[0]
171
- if (!isPrefetch) {
172
- setIds([null, ids[0], ids[1]])
173
- fetchIds(newFirstId, null, true)
174
- }
175
- return { id: prevIds[prevIds.length - 1], idx: prevIds.length - 1 }
176
- }
177
- const fetchedPrevIds = await fetchIds(currIds[0], null, isPrefetch)
178
- const fetchedPrevId = fetchedPrevIds[fetchedPrevIds.length - 1]
179
- return fetchedPrevId ? { id: fetchedPrevId, idx: fetchedPrevIds.length - 1 } : null
180
- },
181
- [ids, fetchIds],
182
- )
183
-
184
- const goNext = useCallback(async () => {
185
- if (itemLoading) return
186
- // case 1: next item ID is fetched
187
- const newPrev = idsRef.current.curr
188
-
189
- setItemLoading(true)
190
- const nextIdData = await getNextId(idIdx, false)
191
- setDirection('next')
192
- if (nextIdData) {
193
- const { id: nextId, idx: nextIdx } = nextIdData
194
- fetchingId.current = nextId
195
- setIdIdx(nextIdx)
196
- updateCurr(nextId)
197
- updateNext(null)
198
- updatePrev(newPrev)
199
- getNextId(nextIdx, true).then(newNextId => updateNext(newNextId?.id ?? null))
200
- } else {
201
- showInfo('No more items')
202
- }
203
- setItemLoading(false)
204
- }, [idIdx, getNextId, updateCurr, updateNext, updatePrev, itemLoading, showInfo])
205
-
206
- const goPrev = useCallback(async () => {
207
- if (itemLoading) return
208
- // case 1: next item ID is fetched
209
- const newNext = idsRef.current.curr
210
-
211
- setDirection('prev')
212
- setItemLoading(true)
213
- const prevIdData = await getPrevId(idIdx, false)
214
- if (prevIdData) {
215
- const { id: prevId, idx: prevIdx } = prevIdData
216
- fetchingId.current = prevId
217
- setIdIdx(prevIdx)
218
- updateCurr(prevId)
219
- updatePrev(null)
220
- updateNext(newNext)
221
- getPrevId(prevIdx, true).then(newPrevId => updatePrev(newPrevId?.id ?? null))
222
- } else {
223
- showInfo('No more items')
224
- }
225
- setItemLoading(false)
226
- }, [idIdx, getPrevId, updateCurr, updateNext, updatePrev, itemLoading, showInfo])
227
-
228
- const refresh = useCallback(async () => {
229
- setLoading(true)
230
- setRefreshing(true)
231
- setIds([null, null, null])
232
- updateCurr(null)
233
- updateNext(null)
234
- updatePrev(null)
235
- setDirection(null)
236
- setIdIdx(0)
237
- await fetchIds(null, null, false)
238
- setRefreshing(false)
239
- }, [fetchIds, updateCurr, updateNext, updatePrev])
240
-
241
- const [initFetchIds] = useState(() => fetchIds)
242
- useEffect(() => {
243
- initFetchIds(null, null, false)
244
- }, [initFetchIds])
245
-
246
- const canGoPrev = useMemo(() => (idIdx > 0 && !!ids[1]?.length) || !!ids[0]?.length, [ids, idIdx])
247
- const canGoNext = useMemo(
248
- () => (ids[1] && idIdx < ids[1].length) ?? !!ids[2]?.length,
249
- [ids, idIdx],
250
- )
251
- return useMemo(
252
- () => ({
253
- ids,
254
- goNext,
255
- goPrev,
256
- error,
257
- refresh,
258
- refreshing,
259
- loading,
260
- canGoNext,
261
- direction,
262
- canGoPrev,
263
- itemLoading,
264
- }),
265
- [
266
- ids,
267
- goNext,
268
- goPrev,
269
- loading,
270
- error,
271
- itemLoading,
272
- canGoNext,
273
- canGoPrev,
274
- refresh,
275
- refreshing,
276
- direction,
277
- ],
278
- )
279
- }
@@ -1,2 +0,0 @@
1
- export { useMediaFeed } from './context'
2
- export * from './MediaFeed'
@@ -1,27 +0,0 @@
1
- import React, { PropsWithChildren, useMemo } from 'react'
2
- import { useWatch } from 'react-hook-form'
3
- import { Animated } from 'react-native'
4
-
5
- export const Condition = ({
6
- path,
7
- condition,
8
- children,
9
- }: PropsWithChildren<{
10
- path: string
11
- condition: (values: any) => boolean
12
- }>) => {
13
- const value = useWatch({ exact: true, name: path })
14
- const isVisible = useMemo(() => condition(value), [value, condition])
15
-
16
- if (!isVisible) return null
17
-
18
- return (
19
- <Animated.View
20
- style={{
21
- paddingVertical: 3,
22
- opacity: 1,
23
- }}>
24
- {children}
25
- </Animated.View>
26
- )
27
- }
@@ -1,44 +0,0 @@
1
- import { InputRef, InputSize, getFieldValidate } from '@chem-po/core'
2
- import { Field, useField } from '@chem-po/react'
3
- import React, { ForwardedRef, forwardRef, useMemo } from 'react'
4
- import { ChangeHandler, Controller } from 'react-hook-form'
5
- import { Input } from './input/input'
6
-
7
- const FieldComponentBase = (
8
- { field, name, size: formSize }: { field: Field; name: string; size?: InputSize },
9
- ref: ForwardedRef<InputRef>,
10
- ) => {
11
- const { control, getOnChange, meta, onFocus, onBlur: fieldBlur } = useField(name, field)
12
- const validate = useMemo(() => field.validate ?? getFieldValidate(field), [field])
13
-
14
- return (
15
- <Controller<Field['defaultValue']>
16
- control={control}
17
- rules={{ validate }}
18
- name={name}
19
- render={({ field: { name: _, ref: _r, onBlur, ...inputProps } }) => {
20
- return (
21
- <Input
22
- ref={ref}
23
- field={field}
24
- input={{
25
- ...inputProps,
26
- onFocus,
27
- onBlur: () => {
28
- fieldBlur()
29
- onBlur()
30
- },
31
- onChange: getOnChange(inputProps.onChange as ChangeHandler),
32
- }}
33
- meta={meta}
34
- formSize={formSize}
35
- />
36
- )
37
- }}
38
- />
39
- )
40
- }
41
-
42
- export const FieldComponent = forwardRef(FieldComponentBase)
43
-
44
- export default FieldComponent