@neko-os/ui 0.5.4 → 0.6.0

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 (135) hide show
  1. package/dist/NekoUI.js +12 -9
  2. package/dist/abstractions/WindowOverlay.js +3 -0
  3. package/dist/abstractions/WindowOverlay.native.js +21 -0
  4. package/dist/abstractions/helpers/storage.js +14 -4
  5. package/dist/abstractions/helpers/storage.native.js +9 -1
  6. package/dist/components/feedback/notifications/NotificationsHandler.js +10 -6
  7. package/dist/components/index.js +3 -1
  8. package/dist/components/inputs/DateInput.js +10 -6
  9. package/dist/components/inputs/InputWrapper.js +2 -3
  10. package/dist/components/inputs/NumberWheelInput.js +50 -0
  11. package/dist/components/inputs/NumberWheelPicker.js +43 -0
  12. package/dist/components/inputs/UploadInput.js +4 -4
  13. package/dist/components/inputs/WheelPicker.js +49 -0
  14. package/dist/components/inputs/WheelPicker.native.js +88 -0
  15. package/dist/components/inputs/WheelPicker.web.js +1 -0
  16. package/dist/components/inputs/dateWheelPicker/DateWheelPicker.js +24 -0
  17. package/dist/components/inputs/dateWheelPicker/DayWheelPicker.js +48 -0
  18. package/dist/components/inputs/dateWheelPicker/MonthWheelPicker.js +19 -0
  19. package/dist/components/inputs/dateWheelPicker/QuarterWheelPicker.js +61 -0
  20. package/dist/components/inputs/dateWheelPicker/WeekWheelPicker.js +66 -0
  21. package/dist/components/inputs/dateWheelPicker/YearWheelPicker.js +35 -0
  22. package/dist/components/inputs/index.js +5 -1
  23. package/dist/components/inputs/upload/Upload.native.js +60 -52
  24. package/dist/components/inputs/upload/useUploadState.js +11 -3
  25. package/dist/components/measurements/FeetInchesInput.js +91 -0
  26. package/dist/components/measurements/LengthInput.js +32 -0
  27. package/dist/components/measurements/LengthText.js +10 -0
  28. package/dist/components/measurements/MeasurementHandler.js +26 -0
  29. package/dist/components/measurements/WeightInput.js +25 -0
  30. package/dist/components/measurements/WeightText.js +10 -0
  31. package/dist/components/measurements/helpers/detectMeasurementSystem.js +15 -0
  32. package/dist/components/measurements/helpers/detectMeasurementSystem.native.js +9 -0
  33. package/dist/components/measurements/helpers/index.js +2 -0
  34. package/dist/components/measurements/helpers/length.js +112 -0
  35. package/dist/components/measurements/helpers/weight.js +56 -0
  36. package/dist/components/measurements/index.js +9 -0
  37. package/dist/components/measurements/useLengthFormatter.js +35 -0
  38. package/dist/components/measurements/useLocalInputValue.js +32 -0
  39. package/dist/components/measurements/useWeightFormatter.js +29 -0
  40. package/dist/components/routing/ReturnButton.js +20 -0
  41. package/dist/components/routing/ReturnButton.native.js +20 -0
  42. package/dist/components/routing/ReturnButton.web.js +2 -0
  43. package/dist/components/routing/ReturnLink.js +25 -0
  44. package/dist/components/routing/ReturnLink.native.js +25 -0
  45. package/dist/components/routing/ReturnLink.web.js +2 -0
  46. package/dist/components/routing/RoutedStepsContent.js +21 -0
  47. package/dist/components/routing/RoutedStepsContent.native.js +94 -0
  48. package/dist/components/routing/RoutedStepsContent.web.js +3 -0
  49. package/dist/components/routing/index.js +3 -0
  50. package/dist/components/state/StatePresenter.js +1 -1
  51. package/dist/components/steps/StepsHandler.js +2 -0
  52. package/dist/components/structure/TopBar.js +18 -16
  53. package/dist/components/theme/ThemePickerDrawer.js +1 -1
  54. package/dist/helpers/compress.js +61 -0
  55. package/dist/helpers/compress.native.js +49 -0
  56. package/dist/helpers/files.js +7 -0
  57. package/dist/helpers/files.native.js +55 -0
  58. package/dist/helpers/index.js +6 -1
  59. package/dist/helpers/media.js +4 -0
  60. package/dist/helpers/media.native.js +41 -0
  61. package/dist/helpers/numbers.js +13 -0
  62. package/dist/helpers/pickAssets.js +7 -0
  63. package/dist/helpers/pickAssets.native.js +66 -0
  64. package/dist/helpers/storage.js +17 -0
  65. package/dist/i18n/I18n.js +4 -4
  66. package/dist/index.js +1 -1
  67. package/dist/responsive/responsiveHooks.js +14 -0
  68. package/package.json +2 -14
  69. package/src/NekoUI.js +16 -13
  70. package/src/abstractions/WindowOverlay.js +3 -0
  71. package/src/abstractions/WindowOverlay.native.js +21 -0
  72. package/src/abstractions/helpers/storage.js +13 -3
  73. package/src/abstractions/helpers/storage.native.js +8 -0
  74. package/src/components/feedback/notifications/NotificationsHandler.js +12 -8
  75. package/src/components/index.js +2 -0
  76. package/src/components/inputs/DateInput.js +8 -4
  77. package/src/components/inputs/InputWrapper.js +1 -2
  78. package/src/components/inputs/NumberWheelInput.js +50 -0
  79. package/src/components/inputs/NumberWheelPicker.js +43 -0
  80. package/src/components/inputs/UploadInput.js +2 -2
  81. package/src/components/inputs/WheelPicker.js +49 -0
  82. package/src/components/inputs/WheelPicker.native.js +88 -0
  83. package/src/components/inputs/WheelPicker.web.js +1 -0
  84. package/src/components/inputs/dateWheelPicker/DateWheelPicker.js +24 -0
  85. package/src/components/inputs/dateWheelPicker/DayWheelPicker.js +48 -0
  86. package/src/components/inputs/dateWheelPicker/MonthWheelPicker.js +19 -0
  87. package/src/components/inputs/dateWheelPicker/QuarterWheelPicker.js +61 -0
  88. package/src/components/inputs/dateWheelPicker/WeekWheelPicker.js +66 -0
  89. package/src/components/inputs/dateWheelPicker/YearWheelPicker.js +35 -0
  90. package/src/components/inputs/index.js +4 -0
  91. package/src/components/inputs/upload/Upload.native.js +58 -50
  92. package/src/components/inputs/upload/useUploadState.js +11 -3
  93. package/src/components/measurements/FeetInchesInput.js +91 -0
  94. package/src/components/measurements/LengthInput.js +32 -0
  95. package/src/components/measurements/LengthText.js +10 -0
  96. package/src/components/measurements/MeasurementHandler.js +26 -0
  97. package/src/components/measurements/WeightInput.js +25 -0
  98. package/src/components/measurements/WeightText.js +10 -0
  99. package/src/components/measurements/helpers/detectMeasurementSystem.js +15 -0
  100. package/src/components/measurements/helpers/detectMeasurementSystem.native.js +9 -0
  101. package/src/components/measurements/helpers/index.js +2 -0
  102. package/src/components/measurements/helpers/length.js +112 -0
  103. package/src/components/measurements/helpers/weight.js +56 -0
  104. package/src/components/measurements/index.js +9 -0
  105. package/src/components/measurements/useLengthFormatter.js +35 -0
  106. package/src/components/measurements/useLocalInputValue.js +32 -0
  107. package/src/components/measurements/useWeightFormatter.js +29 -0
  108. package/src/components/routing/ReturnButton.js +20 -0
  109. package/src/components/routing/ReturnButton.native.js +20 -0
  110. package/src/components/routing/ReturnButton.web.js +2 -0
  111. package/src/components/routing/ReturnLink.js +25 -0
  112. package/src/components/routing/ReturnLink.native.js +25 -0
  113. package/src/components/routing/ReturnLink.web.js +2 -0
  114. package/src/components/routing/RoutedStepsContent.js +21 -0
  115. package/src/components/routing/RoutedStepsContent.native.js +94 -0
  116. package/src/components/routing/RoutedStepsContent.web.js +3 -0
  117. package/src/components/routing/index.js +3 -0
  118. package/src/components/state/StatePresenter.js +1 -1
  119. package/src/components/steps/StepsHandler.js +2 -0
  120. package/src/components/structure/TopBar.js +16 -14
  121. package/src/components/theme/ThemePickerDrawer.js +1 -1
  122. package/src/helpers/compress.js +61 -0
  123. package/src/helpers/compress.native.js +49 -0
  124. package/src/helpers/files.js +7 -0
  125. package/src/helpers/files.native.js +55 -0
  126. package/src/helpers/index.js +6 -1
  127. package/src/helpers/media.js +4 -0
  128. package/src/helpers/media.native.js +41 -0
  129. package/src/helpers/numbers.js +13 -0
  130. package/src/helpers/pickAssets.js +7 -0
  131. package/src/helpers/pickAssets.native.js +66 -0
  132. package/src/helpers/storage.js +17 -0
  133. package/src/i18n/I18n.js +2 -2
  134. package/src/index.js +1 -1
  135. package/src/responsive/responsiveHooks.js +14 -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
+ }
@@ -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) || key
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
@@ -6,4 +6,4 @@ export * from './i18n'
6
6
  export * from './NekoUI'
7
7
  export * from './abstractions'
8
8
 
9
- export const version = 41
9
+ export const version = 44
@@ -27,6 +27,20 @@ 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. Otherwise it is a plain
32
+ // object prop (e.g. titleProps) and must pass through untouched.
33
+ const bpNames = breakpoints.map((b) => b.name)
34
+ const isResponsiveKey = (k) =>
35
+ k === 'df' ||
36
+ k === 'native' ||
37
+ k === 'web' ||
38
+ k === 'ios' ||
39
+ k === 'android' ||
40
+ bpNames.includes(k) ||
41
+ (/^(\w+)[du]$/.test(k) && bpNames.includes(k.slice(0, -1)))
42
+ if (!Object.keys(value).some(isResponsiveKey)) return value
43
+
30
44
  if (value[screen]) return value[screen]
31
45
 
32
46
  const keys = Object.keys(value)