@neko-os/ui 0.5.4 → 0.6.1
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/NekoUI.js +12 -9
- package/dist/abstractions/WindowOverlay.js +3 -0
- package/dist/abstractions/WindowOverlay.native.js +21 -0
- package/dist/abstractions/helpers/storage.js +14 -4
- package/dist/abstractions/helpers/storage.native.js +9 -1
- package/dist/components/feedback/notifications/NotificationsHandler.js +10 -6
- package/dist/components/index.js +3 -1
- package/dist/components/inputs/DateInput.js +10 -6
- package/dist/components/inputs/InputWrapper.js +2 -3
- package/dist/components/inputs/NumberWheelInput.js +50 -0
- package/dist/components/inputs/NumberWheelPicker.js +43 -0
- package/dist/components/inputs/UploadInput.js +4 -4
- package/dist/components/inputs/WheelPicker.js +49 -0
- package/dist/components/inputs/WheelPicker.native.js +88 -0
- package/dist/components/inputs/WheelPicker.web.js +1 -0
- package/dist/components/inputs/dateWheelPicker/DateWheelPicker.js +24 -0
- package/dist/components/inputs/dateWheelPicker/DayWheelPicker.js +48 -0
- package/dist/components/inputs/dateWheelPicker/MonthWheelPicker.js +19 -0
- package/dist/components/inputs/dateWheelPicker/QuarterWheelPicker.js +61 -0
- package/dist/components/inputs/dateWheelPicker/WeekWheelPicker.js +66 -0
- package/dist/components/inputs/dateWheelPicker/YearWheelPicker.js +35 -0
- package/dist/components/inputs/index.js +5 -1
- package/dist/components/inputs/upload/Upload.native.js +60 -52
- package/dist/components/inputs/upload/useUploadState.js +11 -3
- package/dist/components/measurements/FeetInchesInput.js +91 -0
- package/dist/components/measurements/LengthInput.js +32 -0
- package/dist/components/measurements/LengthText.js +10 -0
- package/dist/components/measurements/MeasurementHandler.js +26 -0
- package/dist/components/measurements/WeightInput.js +25 -0
- package/dist/components/measurements/WeightText.js +10 -0
- package/dist/components/measurements/helpers/detectMeasurementSystem.js +15 -0
- package/dist/components/measurements/helpers/detectMeasurementSystem.native.js +9 -0
- package/dist/components/measurements/helpers/index.js +2 -0
- package/dist/components/measurements/helpers/length.js +112 -0
- package/dist/components/measurements/helpers/weight.js +56 -0
- package/dist/components/measurements/index.js +9 -0
- package/dist/components/measurements/useLengthFormatter.js +35 -0
- package/dist/components/measurements/useLocalInputValue.js +32 -0
- package/dist/components/measurements/useWeightFormatter.js +29 -0
- package/dist/components/routing/ReturnButton.js +20 -0
- package/dist/components/routing/ReturnButton.native.js +20 -0
- package/dist/components/routing/ReturnButton.web.js +2 -0
- package/dist/components/routing/ReturnLink.js +25 -0
- package/dist/components/routing/ReturnLink.native.js +25 -0
- package/dist/components/routing/ReturnLink.web.js +2 -0
- package/dist/components/routing/RoutedStepsContent.js +21 -0
- package/dist/components/routing/RoutedStepsContent.native.js +94 -0
- package/dist/components/routing/RoutedStepsContent.web.js +3 -0
- package/dist/components/routing/index.js +3 -0
- package/dist/components/state/StatePresenter.js +1 -1
- package/dist/components/steps/StepsHandler.js +2 -0
- package/dist/components/structure/TopBar.js +18 -16
- package/dist/components/theme/ThemePickerDrawer.js +1 -1
- package/dist/helpers/compress.js +61 -0
- package/dist/helpers/compress.native.js +49 -0
- package/dist/helpers/files.js +7 -0
- package/dist/helpers/files.native.js +55 -0
- package/dist/helpers/index.js +6 -1
- package/dist/helpers/media.js +4 -0
- package/dist/helpers/media.native.js +41 -0
- package/dist/helpers/numbers.js +13 -0
- package/dist/helpers/pickAssets.js +7 -0
- package/dist/helpers/pickAssets.native.js +66 -0
- package/dist/helpers/storage.js +17 -0
- package/dist/i18n/I18n.js +4 -4
- package/dist/index.js +1 -1
- package/dist/responsive/responsiveHooks.js +17 -0
- package/package.json +2 -14
- package/src/NekoUI.js +16 -13
- package/src/abstractions/WindowOverlay.js +3 -0
- package/src/abstractions/WindowOverlay.native.js +21 -0
- package/src/abstractions/helpers/storage.js +13 -3
- package/src/abstractions/helpers/storage.native.js +8 -0
- package/src/components/feedback/notifications/NotificationsHandler.js +12 -8
- package/src/components/index.js +2 -0
- package/src/components/inputs/DateInput.js +8 -4
- package/src/components/inputs/InputWrapper.js +1 -2
- package/src/components/inputs/NumberWheelInput.js +50 -0
- package/src/components/inputs/NumberWheelPicker.js +43 -0
- package/src/components/inputs/UploadInput.js +2 -2
- package/src/components/inputs/WheelPicker.js +49 -0
- package/src/components/inputs/WheelPicker.native.js +88 -0
- package/src/components/inputs/WheelPicker.web.js +1 -0
- package/src/components/inputs/dateWheelPicker/DateWheelPicker.js +24 -0
- package/src/components/inputs/dateWheelPicker/DayWheelPicker.js +48 -0
- package/src/components/inputs/dateWheelPicker/MonthWheelPicker.js +19 -0
- package/src/components/inputs/dateWheelPicker/QuarterWheelPicker.js +61 -0
- package/src/components/inputs/dateWheelPicker/WeekWheelPicker.js +66 -0
- package/src/components/inputs/dateWheelPicker/YearWheelPicker.js +35 -0
- package/src/components/inputs/index.js +4 -0
- package/src/components/inputs/upload/Upload.native.js +58 -50
- package/src/components/inputs/upload/useUploadState.js +11 -3
- package/src/components/measurements/FeetInchesInput.js +91 -0
- package/src/components/measurements/LengthInput.js +32 -0
- package/src/components/measurements/LengthText.js +10 -0
- package/src/components/measurements/MeasurementHandler.js +26 -0
- package/src/components/measurements/WeightInput.js +25 -0
- package/src/components/measurements/WeightText.js +10 -0
- package/src/components/measurements/helpers/detectMeasurementSystem.js +15 -0
- package/src/components/measurements/helpers/detectMeasurementSystem.native.js +9 -0
- package/src/components/measurements/helpers/index.js +2 -0
- package/src/components/measurements/helpers/length.js +112 -0
- package/src/components/measurements/helpers/weight.js +56 -0
- package/src/components/measurements/index.js +9 -0
- package/src/components/measurements/useLengthFormatter.js +35 -0
- package/src/components/measurements/useLocalInputValue.js +32 -0
- package/src/components/measurements/useWeightFormatter.js +29 -0
- package/src/components/routing/ReturnButton.js +20 -0
- package/src/components/routing/ReturnButton.native.js +20 -0
- package/src/components/routing/ReturnButton.web.js +2 -0
- package/src/components/routing/ReturnLink.js +25 -0
- package/src/components/routing/ReturnLink.native.js +25 -0
- package/src/components/routing/ReturnLink.web.js +2 -0
- package/src/components/routing/RoutedStepsContent.js +21 -0
- package/src/components/routing/RoutedStepsContent.native.js +94 -0
- package/src/components/routing/RoutedStepsContent.web.js +3 -0
- package/src/components/routing/index.js +3 -0
- package/src/components/state/StatePresenter.js +1 -1
- package/src/components/steps/StepsHandler.js +2 -0
- package/src/components/structure/TopBar.js +16 -14
- package/src/components/theme/ThemePickerDrawer.js +1 -1
- package/src/helpers/compress.js +61 -0
- package/src/helpers/compress.native.js +49 -0
- package/src/helpers/files.js +7 -0
- package/src/helpers/files.native.js +55 -0
- package/src/helpers/index.js +6 -1
- package/src/helpers/media.js +4 -0
- package/src/helpers/media.native.js +41 -0
- package/src/helpers/numbers.js +13 -0
- package/src/helpers/pickAssets.js +7 -0
- package/src/helpers/pickAssets.native.js +66 -0
- package/src/helpers/storage.js +17 -0
- package/src/i18n/I18n.js +2 -2
- package/src/index.js +1 -1
- package/src/responsive/responsiveHooks.js +17 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { openCamera, openLibrary } from './media'
|
|
2
|
+
import { compressAsset, compressAssets } from './compress'
|
|
3
|
+
import { persistFile } from './files'
|
|
4
|
+
|
|
5
|
+
let MediaLibrary
|
|
6
|
+
try {
|
|
7
|
+
MediaLibrary = require('expo-media-library')
|
|
8
|
+
} catch {}
|
|
9
|
+
|
|
10
|
+
async function saveAssetsToLibrary(assets) {
|
|
11
|
+
if (!MediaLibrary || !assets?.length) return
|
|
12
|
+
try {
|
|
13
|
+
const perm = await MediaLibrary.requestPermissionsAsync(true)
|
|
14
|
+
if (!perm.granted) return
|
|
15
|
+
for (const a of assets) {
|
|
16
|
+
try {
|
|
17
|
+
await MediaLibrary.saveToLibraryAsync(a.uri)
|
|
18
|
+
} catch (e) {
|
|
19
|
+
console.warn('[neko-ui pick] saveToLibrary failed:', e?.message)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
} catch (e) {
|
|
23
|
+
console.warn('[neko-ui pick] saveToLibrary permission error:', e?.message)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function persistAsset(asset, persistTo) {
|
|
28
|
+
if (!persistTo) return asset
|
|
29
|
+
return { ...asset, uri: persistFile(asset.uri, persistTo, { name: asset.name }) }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function processAssets(assets, { compress = true, persistTo } = {}) {
|
|
33
|
+
let result = assets
|
|
34
|
+
if (compress !== false) {
|
|
35
|
+
const compressOpts = typeof compress === 'object' ? compress : {}
|
|
36
|
+
result = await compressAssets(result, compressOpts)
|
|
37
|
+
}
|
|
38
|
+
if (persistTo) {
|
|
39
|
+
result = result.map((a) => persistAsset(a, persistTo))
|
|
40
|
+
}
|
|
41
|
+
return result
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function pickFromCamera({ multiple = false, maxCount, mediaTypes, persistTo, compress, saveToLibrary } = {}) {
|
|
45
|
+
const assets = await openCamera({
|
|
46
|
+
allowsMultipleSelection: multiple,
|
|
47
|
+
selectionLimit: maxCount || 0,
|
|
48
|
+
mediaTypes,
|
|
49
|
+
})
|
|
50
|
+
if (!assets.length) return multiple ? [] : null
|
|
51
|
+
// Save original (pre-compression) captures to device Photos
|
|
52
|
+
if (saveToLibrary) await saveAssetsToLibrary(assets)
|
|
53
|
+
const result = await processAssets(assets, { compress, persistTo })
|
|
54
|
+
return multiple ? result : result[0]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function pickFromLibrary({ multiple = false, maxCount, mediaTypes, persistTo, compress } = {}) {
|
|
58
|
+
const assets = await openLibrary({
|
|
59
|
+
allowsMultipleSelection: multiple,
|
|
60
|
+
selectionLimit: maxCount || 0,
|
|
61
|
+
mediaTypes,
|
|
62
|
+
})
|
|
63
|
+
if (!assets.length) return multiple ? [] : null
|
|
64
|
+
const result = await processAssets(assets, { compress, persistTo })
|
|
65
|
+
return multiple ? result : result[0]
|
|
66
|
+
}
|
package/src/helpers/storage.js
CHANGED
|
@@ -41,6 +41,21 @@ function getAsync(key, defaultValue) {
|
|
|
41
41
|
})
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
function notifyAll(value) {
|
|
45
|
+
Object.keys(listeners).forEach((key) => notify(key, value))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function clear() {
|
|
49
|
+
AbsStorage.clear()
|
|
50
|
+
notifyAll(undefined)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function clearAsync() {
|
|
54
|
+
return AbsStorage.clearAsync().then(() => {
|
|
55
|
+
notifyAll(undefined)
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
44
59
|
function formatStoragedValue(value) {
|
|
45
60
|
try {
|
|
46
61
|
if (!value) return value
|
|
@@ -73,5 +88,7 @@ export const Storage = {
|
|
|
73
88
|
setAsync,
|
|
74
89
|
get,
|
|
75
90
|
getAsync,
|
|
91
|
+
clear,
|
|
92
|
+
clearAsync,
|
|
76
93
|
useState,
|
|
77
94
|
}
|
package/src/i18n/I18n.js
CHANGED
|
@@ -26,7 +26,7 @@ export class I18n {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
t(key, opts = {}) {
|
|
29
|
-
let { ns = 'common', context, ...vars } = opts
|
|
29
|
+
let { ns = 'common', context, default: defaultVal, ...vars } = opts
|
|
30
30
|
const count = vars?.count
|
|
31
31
|
if (key.includes(':')) {
|
|
32
32
|
const splittedKey = key.split(':')
|
|
@@ -39,7 +39,7 @@ export class I18n {
|
|
|
39
39
|
|
|
40
40
|
if (!value) {
|
|
41
41
|
const fallbackData = this.resources[this.fallback]?.[ns]
|
|
42
|
-
value = this._resolveKey(fallbackData, key, count, context)
|
|
42
|
+
value = this._resolveKey(fallbackData, key, count, context) ?? defaultVal ?? key
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
return this._interpolate(value, vars)
|
package/src/index.js
CHANGED
|
@@ -27,6 +27,23 @@ export function useGetResponsiveValue() {
|
|
|
27
27
|
|
|
28
28
|
if (!isObj) return value
|
|
29
29
|
|
|
30
|
+
// Only treat the object as a responsive descriptor when it actually
|
|
31
|
+
// carries breakpoint / platform / df keys. A non-empty plain object
|
|
32
|
+
// (e.g. titleProps) passes through untouched. An empty object carries
|
|
33
|
+
// no info either way, so it falls through to the df (undefined) result
|
|
34
|
+
// instead of returning itself truthy.
|
|
35
|
+
const bpNames = breakpoints.map((b) => b.name)
|
|
36
|
+
const isResponsiveKey = (k) =>
|
|
37
|
+
k === 'df' ||
|
|
38
|
+
k === 'native' ||
|
|
39
|
+
k === 'web' ||
|
|
40
|
+
k === 'ios' ||
|
|
41
|
+
k === 'android' ||
|
|
42
|
+
bpNames.includes(k) ||
|
|
43
|
+
(/^(\w+)[du]$/.test(k) && bpNames.includes(k.slice(0, -1)))
|
|
44
|
+
const objKeys = Object.keys(value)
|
|
45
|
+
if (objKeys.length > 0 && !objKeys.some(isResponsiveKey)) return value
|
|
46
|
+
|
|
30
47
|
if (value[screen]) return value[screen]
|
|
31
48
|
|
|
32
49
|
const keys = Object.keys(value)
|