vueless 0.0.478 → 0.0.480

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 (297) hide show
  1. package/adatper.locale/vue-i18n.ts +14 -0
  2. package/adatper.locale/{vueless.js → vueless.ts} +67 -19
  3. package/composables/useAutoPosition.ts +113 -0
  4. package/composables/useBreakpoint.ts +109 -0
  5. package/composables/useLocale.ts +22 -0
  6. package/composables/useMutationObserver.ts +53 -0
  7. package/composables/{useUI.js → useUI.ts} +109 -105
  8. package/constants.js +124 -2
  9. package/directives/clickOutside/storybook/Docs.mdx +1 -1
  10. package/directives/clickOutside/storybook/{stories.js → stories.ts} +7 -9
  11. package/directives/clickOutside/types.ts +22 -0
  12. package/directives/clickOutside/vClickOutside.ts +96 -0
  13. package/directives/index.js +7 -2
  14. package/directives/tooltip/storybook/Docs.mdx +1 -1
  15. package/directives/tooltip/storybook/{stories.js → stories.ts} +22 -10
  16. package/directives/tooltip/types.ts +14 -0
  17. package/directives/tooltip/vTooltip.ts +82 -0
  18. package/{index.js → index.ts} +12 -9
  19. package/package.json +38 -25
  20. package/plugin-vite.d.ts +10 -0
  21. package/plugin-vite.js +97 -0
  22. package/{preset.tailwind.js → preset-tailwind.js} +21 -7
  23. package/types.ts +322 -0
  24. package/ui.button/UButton.vue +1 -1
  25. package/ui.button/storybook/Docs.mdx +1 -1
  26. package/ui.button/storybook/stories.js +11 -6
  27. package/ui.button/useAttrs.js +1 -1
  28. package/ui.button-link/ULink.vue +2 -2
  29. package/ui.button-link/storybook/Docs.mdx +1 -1
  30. package/ui.button-link/storybook/stories.js +2 -2
  31. package/ui.button-link/useAttrs.js +1 -1
  32. package/ui.button-toggle/UToggle.vue +1 -1
  33. package/ui.button-toggle/storybook/Docs.mdx +1 -1
  34. package/ui.button-toggle/storybook/stories.js +2 -2
  35. package/ui.button-toggle/useAttrs.js +1 -1
  36. package/ui.button-toggle-item/UToggleItem.vue +1 -1
  37. package/ui.button-toggle-item/storybook/Docs.mdx +1 -1
  38. package/ui.button-toggle-item/storybook/stories.js +1 -1
  39. package/ui.button-toggle-item/useAttrs.js +1 -1
  40. package/ui.container-accordion/UAccordion.vue +1 -1
  41. package/ui.container-accordion/storybook/Docs.mdx +1 -1
  42. package/ui.container-accordion/storybook/stories.js +1 -1
  43. package/ui.container-accordion/useAttrs.js +1 -1
  44. package/ui.container-card/storybook/Docs.mdx +1 -1
  45. package/ui.container-card/storybook/stories.js +1 -1
  46. package/ui.container-card/useAttrs.js +1 -1
  47. package/ui.container-col/UCol.vue +1 -1
  48. package/ui.container-col/storybook/Docs.mdx +1 -1
  49. package/ui.container-col/storybook/stories.js +1 -1
  50. package/ui.container-col/useAttrs.js +1 -1
  51. package/ui.container-divider/UDivider.vue +1 -1
  52. package/ui.container-divider/storybook/Docs.mdx +1 -1
  53. package/ui.container-divider/storybook/stories.js +2 -2
  54. package/ui.container-divider/useAttrs.js +1 -1
  55. package/ui.container-group/UGroup.vue +1 -1
  56. package/ui.container-group/storybook/Docs.mdx +1 -1
  57. package/ui.container-group/storybook/stories.js +1 -1
  58. package/ui.container-group/useAttrs.js +1 -1
  59. package/ui.container-modal/UModal.vue +1 -1
  60. package/ui.container-modal/storybook/Docs.mdx +1 -1
  61. package/ui.container-modal/storybook/stories.js +2 -2
  62. package/ui.container-modal/useAttrs.js +1 -1
  63. package/ui.container-modal-confirm/UModalConfirm.vue +2 -2
  64. package/ui.container-modal-confirm/storybook/Docs.mdx +1 -1
  65. package/ui.container-modal-confirm/storybook/stories.js +2 -2
  66. package/ui.container-modal-confirm/useAttrs.js +1 -1
  67. package/ui.container-page/UPage.vue +2 -2
  68. package/ui.container-page/storybook/Docs.mdx +1 -1
  69. package/ui.container-page/storybook/stories.js +1 -1
  70. package/ui.container-page/useAttrs.js +2 -2
  71. package/ui.container-row/URow.vue +1 -1
  72. package/ui.container-row/storybook/Docs.mdx +1 -1
  73. package/ui.container-row/storybook/stories.js +2 -2
  74. package/ui.container-row/useAttrs.js +1 -1
  75. package/ui.data-list/UDataList.vue +6 -6
  76. package/ui.data-list/storybook/Docs.mdx +1 -1
  77. package/ui.data-list/storybook/stories.js +1 -1
  78. package/ui.data-list/useAttrs.js +1 -1
  79. package/ui.data-table/UTable.vue +3 -3
  80. package/ui.data-table/UTableRow.vue +7 -6
  81. package/ui.data-table/config.js +10 -3
  82. package/ui.data-table/storybook/Docs.mdx +1 -1
  83. package/ui.data-table/storybook/stories.js +5 -3
  84. package/ui.data-table/useAttrs.js +1 -1
  85. package/ui.data-table/utilTable.js +1 -1
  86. package/ui.dropdown-badge/UDropdownBadge.vue +1 -1
  87. package/ui.dropdown-badge/storybook/Docs.mdx +1 -1
  88. package/ui.dropdown-badge/storybook/stories.js +2 -2
  89. package/ui.dropdown-badge/useAttrs.js +1 -1
  90. package/ui.dropdown-button/UDropdownButton.vue +1 -1
  91. package/ui.dropdown-button/storybook/Docs.mdx +1 -1
  92. package/ui.dropdown-button/storybook/stories.js +3 -3
  93. package/ui.dropdown-button/useAttrs.js +1 -1
  94. package/ui.dropdown-link/UDropdownLink.vue +1 -1
  95. package/ui.dropdown-link/config.js +1 -1
  96. package/ui.dropdown-link/storybook/Docs.mdx +1 -1
  97. package/ui.dropdown-link/storybook/stories.js +2 -2
  98. package/ui.dropdown-link/useAttrs.js +4 -6
  99. package/ui.dropdown-list/UDropdownList.vue +3 -3
  100. package/ui.dropdown-list/storybook/Docs.mdx +1 -1
  101. package/ui.dropdown-list/storybook/stories.js +2 -2
  102. package/ui.dropdown-list/useAttrs.js +1 -1
  103. package/ui.form-calendar/UCalendar.vue +2 -2
  104. package/ui.form-calendar/storybook/Docs.mdx +1 -1
  105. package/ui.form-calendar/storybook/stories.js +1 -1
  106. package/ui.form-calendar/useAttrs.js +1 -1
  107. package/ui.form-checkbox/UCheckbox.vue +1 -1
  108. package/ui.form-checkbox/storybook/Docs.mdx +1 -1
  109. package/ui.form-checkbox/storybook/stories.js +2 -2
  110. package/ui.form-checkbox/useAttrs.js +1 -1
  111. package/ui.form-checkbox-group/UCheckboxGroup.vue +1 -1
  112. package/ui.form-checkbox-group/storybook/Docs.mdx +1 -1
  113. package/ui.form-checkbox-group/storybook/stories.js +2 -2
  114. package/ui.form-checkbox-group/useAttrs.js +1 -1
  115. package/ui.form-checkbox-multi-state/UCheckboxMultiState.vue +1 -1
  116. package/ui.form-checkbox-multi-state/storybook/Docs.mdx +1 -1
  117. package/ui.form-checkbox-multi-state/storybook/stories.js +2 -2
  118. package/ui.form-checkbox-multi-state/useAttrs.js +1 -1
  119. package/ui.form-color-picker/UColorPicker.vue +1 -1
  120. package/ui.form-color-picker/storybook/Docs.mdx +1 -1
  121. package/ui.form-color-picker/storybook/stories.js +2 -2
  122. package/ui.form-color-picker/useAttrs.js +1 -1
  123. package/ui.form-date-picker/UDatePicker.vue +4 -7
  124. package/ui.form-date-picker/storybook/Docs.mdx +1 -1
  125. package/ui.form-date-picker/storybook/stories.js +3 -3
  126. package/ui.form-date-picker/useAttrs.js +2 -2
  127. package/ui.form-date-picker-range/UDatePickerRange.vue +2 -2
  128. package/ui.form-date-picker-range/storybook/Docs.mdx +1 -1
  129. package/ui.form-date-picker-range/storybook/stories.js +2 -2
  130. package/ui.form-date-picker-range/useAttrs.js +2 -2
  131. package/ui.form-date-picker-range/useLocale.js +1 -1
  132. package/ui.form-input/UInput.vue +3 -3
  133. package/ui.form-input/storybook/Docs.mdx +1 -1
  134. package/ui.form-input/storybook/stories.js +2 -2
  135. package/ui.form-input/useAttrs.js +1 -1
  136. package/ui.form-input-file/UInputFile.vue +2 -2
  137. package/ui.form-input-file/storybook/Docs.mdx +1 -1
  138. package/ui.form-input-file/storybook/stories.js +2 -2
  139. package/ui.form-input-file/useAttrs.js +1 -1
  140. package/ui.form-input-money/UInputMoney.vue +1 -1
  141. package/ui.form-input-money/storybook/Docs.mdx +1 -1
  142. package/ui.form-input-money/storybook/stories.js +2 -2
  143. package/ui.form-input-money/useAttrs.js +1 -1
  144. package/ui.form-input-money/useFormatCurrency.js +1 -1
  145. package/ui.form-input-number/UInputNumber.vue +5 -4
  146. package/ui.form-input-number/storybook/Docs.mdx +1 -1
  147. package/ui.form-input-number/storybook/stories.js +2 -2
  148. package/ui.form-input-number/useAttrs.js +1 -1
  149. package/ui.form-input-rating/UInputRating.vue +1 -1
  150. package/ui.form-input-rating/storybook/Docs.mdx +1 -1
  151. package/ui.form-input-rating/storybook/stories.js +2 -2
  152. package/ui.form-input-rating/useAttrs.js +1 -1
  153. package/ui.form-input-search/UInputSearch.vue +2 -2
  154. package/ui.form-input-search/storybook/Docs.mdx +1 -1
  155. package/ui.form-input-search/storybook/stories.js +2 -2
  156. package/ui.form-input-search/useAttrs.js +1 -1
  157. package/ui.form-label/ULabel.vue +1 -1
  158. package/ui.form-label/config.js +2 -2
  159. package/ui.form-label/storybook/Docs.mdx +1 -1
  160. package/ui.form-label/storybook/stories.js +2 -2
  161. package/ui.form-label/useAttrs.js +1 -1
  162. package/ui.form-radio/URadio.vue +1 -1
  163. package/ui.form-radio/storybook/Docs.mdx +1 -1
  164. package/ui.form-radio/storybook/stories.js +1 -1
  165. package/ui.form-radio/useAttrs.js +1 -1
  166. package/ui.form-radio-group/URadioGroup.vue +1 -1
  167. package/ui.form-radio-group/storybook/Docs.mdx +1 -1
  168. package/ui.form-radio-group/storybook/stories.js +2 -2
  169. package/ui.form-radio-group/useAttrs.js +1 -1
  170. package/ui.form-select/USelect.vue +4 -4
  171. package/ui.form-select/storybook/Docs.mdx +1 -1
  172. package/ui.form-select/storybook/stories.js +2 -2
  173. package/ui.form-select/useAttrs.js +1 -1
  174. package/ui.form-switch/USwitch.vue +2 -2
  175. package/ui.form-switch/storybook/Docs.mdx +1 -1
  176. package/ui.form-switch/storybook/stories.js +2 -2
  177. package/ui.form-switch/useAttrs.js +1 -1
  178. package/ui.form-switch/utilVariant.js +1 -1
  179. package/ui.form-textarea/UTextarea.vue +1 -1
  180. package/ui.form-textarea/storybook/Docs.mdx +1 -1
  181. package/ui.form-textarea/storybook/stories.js +2 -2
  182. package/ui.form-textarea/useAttrs.js +1 -1
  183. package/ui.image-avatar/UAvatar.vue +1 -1
  184. package/ui.image-avatar/storybook/Docs.mdx +1 -1
  185. package/ui.image-avatar/storybook/stories.js +2 -2
  186. package/ui.image-avatar/useAttrs.js +1 -1
  187. package/ui.image-icon/UIcon.vue +23 -8
  188. package/ui.image-icon/storybook/Docs.mdx +2 -2
  189. package/ui.image-icon/storybook/stories.js +2 -2
  190. package/ui.image-icon/useAttrs.js +2 -2
  191. package/ui.loader/ULoader.vue +1 -1
  192. package/ui.loader/storybook/Docs.mdx +1 -1
  193. package/ui.loader/storybook/stories.js +2 -2
  194. package/ui.loader/useAttrs.js +1 -1
  195. package/ui.loader-overlay/ULoaderOverlay.vue +1 -1
  196. package/ui.loader-overlay/storybook/Docs.mdx +1 -1
  197. package/ui.loader-overlay/storybook/stories.js +1 -1
  198. package/ui.loader-overlay/useAttrs.js +1 -1
  199. package/ui.loader-progress/ULoaderProgress.vue +33 -48
  200. package/ui.loader-progress/constants.js +1 -0
  201. package/ui.loader-progress/storybook/Docs.mdx +1 -1
  202. package/ui.loader-progress/storybook/stories.js +3 -4
  203. package/ui.loader-progress/useAttrs.js +1 -1
  204. package/ui.loader-progress/useLoaderProgress.js +13 -8
  205. package/ui.loader-progress/utilLoaderProgress.js +1 -1
  206. package/ui.navigation-pagination/UPagination.vue +1 -1
  207. package/ui.navigation-pagination/storybook/Docs.mdx +1 -1
  208. package/ui.navigation-pagination/storybook/stories.js +1 -1
  209. package/ui.navigation-pagination/useAttrs.js +1 -1
  210. package/ui.navigation-progress/UProgress.vue +1 -1
  211. package/ui.navigation-progress/storybook/Docs.mdx +1 -1
  212. package/ui.navigation-progress/storybook/stories.js +2 -2
  213. package/ui.navigation-progress/useAttrs.js +1 -1
  214. package/ui.navigation-tab/UTab.vue +1 -1
  215. package/ui.navigation-tab/storybook/Docs.mdx +1 -1
  216. package/ui.navigation-tab/storybook/stories.js +1 -1
  217. package/ui.navigation-tab/useAttrs.js +1 -1
  218. package/ui.navigation-tabs/UTabs.vue +1 -1
  219. package/ui.navigation-tabs/storybook/Docs.mdx +1 -1
  220. package/ui.navigation-tabs/storybook/stories.js +2 -2
  221. package/ui.navigation-tabs/useAttrs.js +1 -1
  222. package/ui.other-dot/UDot.vue +1 -1
  223. package/ui.other-dot/storybook/Docs.mdx +1 -1
  224. package/ui.other-dot/storybook/stories.js +2 -2
  225. package/ui.other-dot/useAttrs.js +1 -1
  226. package/ui.text-alert/UAlert.vue +1 -1
  227. package/ui.text-alert/storybook/Docs.mdx +1 -1
  228. package/ui.text-alert/storybook/stories.js +2 -2
  229. package/ui.text-alert/useAttrs.js +1 -1
  230. package/ui.text-badge/UBadge.vue +89 -179
  231. package/ui.text-badge/storybook/Docs.mdx +3 -3
  232. package/ui.text-badge/storybook/{stories.js → stories.ts} +33 -37
  233. package/ui.text-badge/types.ts +84 -0
  234. package/ui.text-badge/useAttrs.ts +28 -0
  235. package/ui.text-block/UText.vue +18 -62
  236. package/ui.text-block/storybook/Docs.mdx +3 -3
  237. package/ui.text-block/storybook/{stories.js → stories.ts} +13 -8
  238. package/ui.text-block/types.ts +33 -0
  239. package/ui.text-block/useAttrs.ts +20 -0
  240. package/ui.text-empty/UEmpty.vue +1 -1
  241. package/ui.text-empty/storybook/Docs.mdx +1 -1
  242. package/ui.text-empty/storybook/stories.js +2 -2
  243. package/ui.text-empty/useAttrs.js +1 -1
  244. package/ui.text-file/UFile.vue +13 -16
  245. package/ui.text-file/config.js +12 -2
  246. package/ui.text-file/storybook/Docs.mdx +1 -1
  247. package/ui.text-file/storybook/stories.js +1 -1
  248. package/ui.text-file/useAttrs.js +1 -1
  249. package/ui.text-files/UFiles.vue +1 -1
  250. package/ui.text-files/config.js +1 -1
  251. package/ui.text-files/storybook/Docs.mdx +1 -1
  252. package/ui.text-files/storybook/stories.js +1 -1
  253. package/ui.text-files/useAttrs.js +1 -1
  254. package/ui.text-header/UHeader.vue +1 -1
  255. package/ui.text-header/storybook/Docs.mdx +1 -1
  256. package/ui.text-header/storybook/stories.js +2 -2
  257. package/ui.text-header/useAttrs.js +1 -1
  258. package/ui.text-money/UMoney.vue +1 -1
  259. package/ui.text-money/storybook/Docs.mdx +1 -1
  260. package/ui.text-money/storybook/stories.js +2 -2
  261. package/ui.text-money/useAttrs.js +1 -1
  262. package/ui.text-money/utilMoney.js +2 -2
  263. package/ui.text-notify/UNotify.vue +2 -2
  264. package/ui.text-notify/storybook/Docs.mdx +1 -1
  265. package/ui.text-notify/storybook/stories.js +1 -1
  266. package/ui.text-notify/useAttrs.js +1 -1
  267. package/ui.text-notify/utilNotify.js +1 -1
  268. package/utils/{utilHelper.js → helper.ts} +14 -27
  269. package/utils/node/helper.js +78 -0
  270. package/utils/node/loaderIcon.js +232 -0
  271. package/utils/node/loaderSvg.js +71 -0
  272. package/utils/node/mergeConfigs.js +199 -0
  273. package/utils/node/tailwindSafelist.js +366 -0
  274. package/utils/node/vuelessConfig.js +42 -0
  275. package/utils/node/vuelessResolver.js +28 -0
  276. package/utils/{utilPlatform.js → platform.ts} +10 -3
  277. package/utils/{utilStorybook.js → storybook.ts} +102 -36
  278. package/utils/tailwindConfig.ts +33 -0
  279. package/utils/{utilTheme.js → theme.ts} +65 -30
  280. package/utils/ui.ts +129 -0
  281. package/web-types.json +1362 -157
  282. package/adatper.locale/vue-i18n.js +0 -11
  283. package/composables/useAutoPosition.js +0 -94
  284. package/composables/useBreakpoint.js +0 -104
  285. package/composables/useLocale.js +0 -25
  286. package/composables/useMutationObserver.js +0 -48
  287. package/directives/clickOutside/vClickOutside.js +0 -64
  288. package/directives/tooltip/vTooltip.js +0 -56
  289. package/ui.text-badge/useAttrs.js +0 -23
  290. package/ui.text-block/useAttrs.js +0 -15
  291. package/utils/utilUI.js +0 -360
  292. /package/adatper.locale/locales/{en.js → en.ts} +0 -0
  293. /package/ui.image-icon/{config.js → config.ts} +0 -0
  294. /package/ui.text-badge/{config.js → config.ts} +0 -0
  295. /package/ui.text-badge/{constants.js → constants.ts} +0 -0
  296. /package/ui.text-block/{config.js → config.ts} +0 -0
  297. /package/ui.text-block/{constants.js → constants.ts} +0 -0
@@ -0,0 +1,14 @@
1
+ import type { I18n } from "vue-i18n";
2
+
3
+ export default function createVueI18nAdapter(i18n: I18n) {
4
+ return {
5
+ name: "vue-i18n",
6
+ locale: i18n.global.locale,
7
+ fallback: i18n.global.fallbackLocale,
8
+ messages: i18n.global.messages,
9
+ // @ts-expect-error Type instantiation is excessively deep and possibly infinite
10
+ t: (key: string, ...params: unknown[]) => i18n.global.t(key, params),
11
+ tm: i18n.global.tm,
12
+ n: i18n.global.n,
13
+ };
14
+ }
@@ -1,11 +1,35 @@
1
1
  import { shallowRef, ref } from "vue";
2
2
  import { merge } from "lodash-es";
3
3
 
4
- import en from "./locales/en.js";
4
+ import en from "./locales/en.ts";
5
+
6
+ import type { Ref } from "vue";
7
+ import type { UnknownObject } from "../types.ts";
8
+
9
+ export interface LocaleMessages {
10
+ [key: string]: LocaleMessages | string;
11
+ }
12
+
13
+ export interface LocaleOptions {
14
+ messages?: LocaleMessages;
15
+ locale?: string;
16
+ fallback?: string;
17
+ adapter?: LocaleInstance;
18
+ }
19
+
20
+ export interface LocaleInstance {
21
+ name: string;
22
+ messages: Ref<LocaleMessages>;
23
+ locale: Ref<string>;
24
+ fallback: Ref<string>;
25
+ t: (key: string, ...params: unknown[]) => string;
26
+ n: (value: number) => string;
27
+ tm: (key: string, ...params: unknown[]) => string;
28
+ }
5
29
 
6
30
  const FALLBACK_LOCALE_CODE = "en";
7
31
 
8
- export default function createVuelessAdapter(options) {
32
+ export default function createVuelessAdapter(options?: LocaleOptions): LocaleInstance {
9
33
  const current = shallowRef(options?.locale ?? FALLBACK_LOCALE_CODE);
10
34
  const fallback = shallowRef(options?.fallback ?? FALLBACK_LOCALE_CODE);
11
35
 
@@ -22,12 +46,16 @@ export default function createVuelessAdapter(options) {
22
46
  };
23
47
  }
24
48
 
25
- function createTranslateFunction(current, fallback, messages) {
26
- return (key, ...params) => {
49
+ function createTranslateFunction(
50
+ current: Ref<string>,
51
+ fallback: Ref<string>,
52
+ messages: Ref<LocaleMessages>,
53
+ ) {
54
+ return (key: string, ...params: unknown[]) => {
27
55
  const currentLocale = current.value && messages.value[current.value];
28
56
  const fallbackLocale = fallback.value && messages.value[fallback.value];
29
57
 
30
- let str = getObjectValueByPath(currentLocale, key, null);
58
+ let str = getObjectValueByPath<LocaleMessages | string, unknown>(currentLocale, key, null);
31
59
 
32
60
  if (!str) {
33
61
  // eslint-disable-next-line no-console
@@ -49,16 +77,20 @@ function createTranslateFunction(current, fallback, messages) {
49
77
  str = key;
50
78
  }
51
79
 
52
- return replace(str, params);
80
+ return replace(String(str), params);
53
81
  };
54
82
  }
55
83
 
56
- function createTranslateMessageFunction(current, fallback, messages) {
57
- return (key) => {
84
+ function createTranslateMessageFunction(
85
+ current: Ref<string>,
86
+ fallback: Ref<string>,
87
+ messages: Ref<LocaleMessages>,
88
+ ) {
89
+ return (key: string) => {
58
90
  const currentLocale = current.value && messages.value[current.value];
59
91
  const fallbackLocale = fallback.value && messages.value[fallback.value];
60
92
 
61
- let str = getObjectValueByPath(currentLocale, key, null);
93
+ let str = getObjectValueByPath<LocaleMessages | string, unknown>(currentLocale, key, null);
62
94
 
63
95
  if (str === undefined) {
64
96
  // eslint-disable-next-line no-console
@@ -68,51 +100,67 @@ function createTranslateMessageFunction(current, fallback, messages) {
68
100
  str = getObjectValueByPath(fallbackLocale, key, null);
69
101
  }
70
102
 
71
- return str;
103
+ return String(str);
72
104
  };
73
105
  }
74
106
 
75
- const replace = (str, params) => {
107
+ const replace = (str: string, params: unknown[]) => {
76
108
  return str.replace(/\{(\d+)\}/g, (match, index) => {
77
109
  return String(params[+index]);
78
110
  });
79
111
  };
80
112
 
81
- function createNumberFunction(current, fallback) {
82
- return (value, options) => {
113
+ function createNumberFunction(current: Ref<string>, fallback: Ref<string>) {
114
+ return (value: number, options?: Intl.NumberFormatOptions) => {
83
115
  const numberFormat = new Intl.NumberFormat([current.value, fallback.value], options);
84
116
 
85
117
  return numberFormat.format(value);
86
118
  };
87
119
  }
88
120
 
89
- export function getObjectValueByPath(obj, path, fallback) {
121
+ export function getObjectValueByPath<T, K = unknown>(
122
+ obj: T,
123
+ path?: string,
124
+ fallback?: K,
125
+ ): K | undefined {
90
126
  if (obj == null || !path || typeof path !== "string") return fallback;
91
- if (obj[path] !== undefined) return obj[path];
127
+
128
+ const unknownObject = obj as UnknownObject;
129
+
130
+ if (unknownObject[path] !== undefined) {
131
+ return unknownObject[path] as K;
132
+ }
133
+
92
134
  path = path.replace(/\[(\w+)\]/g, ".$1"); // convert indexes to properties
93
135
  path = path.replace(/^\./, ""); // strip a leading dot
94
136
 
95
137
  return getNestedValue(obj, path.split("."), fallback);
96
138
  }
97
139
 
98
- export function getNestedValue(obj, path, fallback) {
140
+ export function getNestedValue<T, K = unknown>(
141
+ obj: T | null | undefined,
142
+ path: (string | number)[],
143
+ fallback?: K,
144
+ ): K | undefined {
99
145
  const last = path.length - 1;
100
146
 
101
147
  if (last < 0) {
102
- return obj === undefined ? fallback : obj;
148
+ return obj === undefined ? fallback : (obj as unknown as K);
103
149
  }
104
150
 
151
+ const unknownObject = obj as Record<string | number, unknown>;
152
+
105
153
  for (let i = 0; i < last; i++) {
106
154
  if (obj == null) {
107
155
  return fallback;
108
156
  }
109
157
 
110
- obj = obj[path[i]];
158
+ obj = unknownObject[path[i]] as T;
111
159
  }
112
160
 
113
161
  if (obj == null) {
114
162
  return fallback;
115
163
  }
116
164
 
117
- return obj[path[last]] === undefined ? fallback : obj[path[last]];
165
+ return (unknownObject[path[last]] === undefined ? fallback : unknownObject[path[last]]) as K;
118
166
  }
@@ -0,0 +1,113 @@
1
+ import { computed, toValue, ref } from "vue";
2
+ import { isSSR } from "../utils/helper.ts";
3
+
4
+ import type { ComputedRef, MaybeRef, Reactive } from "vue";
5
+
6
+ export enum Direction {
7
+ Left = "left",
8
+ Right = "right",
9
+ Top = "top",
10
+ Bottom = "bottom",
11
+ Auto = "auto",
12
+ }
13
+
14
+ export type Align = `${Direction}`;
15
+ export type Position = { x: Align; y: Align };
16
+
17
+ // TODO: Remove it after ui.form-date-picker-range and ui.form-date-picker ts migration (use enum there instead).
18
+ export const POSITION = {
19
+ left: "left",
20
+ right: "right",
21
+ top: "top",
22
+ bottom: "bottom",
23
+ auto: "auto",
24
+ };
25
+
26
+ export function useAutoPosition(
27
+ anchorElement: MaybeRef<HTMLElement | null>,
28
+ targetElement: MaybeRef<HTMLElement | null>,
29
+ position: Reactive<Position> | ComputedRef<Position>,
30
+ preferredPosition: Reactive<Position> | ComputedRef<Position>,
31
+ ) {
32
+ const localAnchorElement = computed(() => toValue(anchorElement));
33
+ const localTargetElement = computed(() => toValue(targetElement));
34
+ const localPosition = computed(() => toValue(position));
35
+ const localPreferredPosition = computed(() => toValue(preferredPosition));
36
+
37
+ const preferredOpenDirectionY = ref(localPreferredPosition.value.y || Direction.Bottom);
38
+ const preferredOpenDirectionX = ref(localPreferredPosition.value.x || Direction.Left);
39
+
40
+ const isTop = computed(() => {
41
+ if (localPosition.value.y !== Direction.Auto) {
42
+ return localPosition.value.y === Direction.Top;
43
+ }
44
+
45
+ return preferredOpenDirectionY.value === Direction.Top;
46
+ });
47
+
48
+ const isLeft = computed(() => {
49
+ if (localPosition.value.x !== Direction.Auto) {
50
+ return localPosition.value.x === Direction.Left;
51
+ }
52
+
53
+ return preferredOpenDirectionX.value === Direction.Left;
54
+ });
55
+
56
+ const isBottom = computed(() => {
57
+ if (localPosition.value.y !== Direction.Auto) {
58
+ return localPosition.value.y === Direction.Bottom;
59
+ }
60
+
61
+ return preferredOpenDirectionY.value === Direction.Bottom;
62
+ });
63
+
64
+ const isRight = computed(() => {
65
+ if (localPosition.value.x !== Direction.Auto) {
66
+ return localPosition.value.x === Direction.Right;
67
+ }
68
+
69
+ return preferredOpenDirectionX.value === Direction.Right;
70
+ });
71
+
72
+ function adjustPositionY() {
73
+ if (isSSR || !localAnchorElement.value || !localTargetElement.value) return;
74
+
75
+ const spaceAbove = localAnchorElement.value.getBoundingClientRect().top;
76
+ const spaceBelow = window.innerHeight - localAnchorElement.value.getBoundingClientRect().bottom;
77
+ const hasEnoughSpaceBelow =
78
+ spaceBelow > localTargetElement.value.getBoundingClientRect().height;
79
+ const hasEnoughSpaceAbove =
80
+ spaceAbove > localTargetElement.value.getBoundingClientRect().height;
81
+
82
+ if (localPreferredPosition.value.y === Direction.Bottom) {
83
+ preferredOpenDirectionY.value =
84
+ hasEnoughSpaceBelow || spaceBelow > spaceAbove ? Direction.Bottom : Direction.Top;
85
+ }
86
+
87
+ if (localPreferredPosition.value.y === Direction.Top) {
88
+ preferredOpenDirectionY.value =
89
+ hasEnoughSpaceAbove || spaceAbove > spaceBelow ? Direction.Top : Direction.Bottom;
90
+ }
91
+ }
92
+
93
+ function adjustPositionX() {
94
+ if (isSSR || !localAnchorElement.value || !localTargetElement.value) return;
95
+
96
+ const spaceRight = localAnchorElement.value.getBoundingClientRect().right;
97
+ const spaceLeft = window.innerWidth - localAnchorElement.value.getBoundingClientRect().left;
98
+ const hasEnoughSpaceLeft = spaceLeft > localTargetElement.value.getBoundingClientRect().width;
99
+ const hasEnoughSpaceRight = spaceRight > localTargetElement.value.getBoundingClientRect().width;
100
+
101
+ if (localPreferredPosition.value.x === Direction.Right) {
102
+ preferredOpenDirectionX.value =
103
+ hasEnoughSpaceRight || spaceRight > spaceLeft ? Direction.Right : Direction.Left;
104
+ }
105
+
106
+ if (localPreferredPosition.value.x === Direction.Left) {
107
+ preferredOpenDirectionX.value =
108
+ hasEnoughSpaceLeft || spaceLeft > spaceRight ? Direction.Left : Direction.Right;
109
+ }
110
+ }
111
+
112
+ return { isTop, isRight, isBottom, isLeft, adjustPositionY, adjustPositionX };
113
+ }
@@ -0,0 +1,109 @@
1
+ import { onMounted, ref, watch, computed, onBeforeUnmount } from "vue";
2
+ import { isSSR } from "../utils/helper.ts";
3
+
4
+ import type { Ref } from "vue";
5
+
6
+ enum BreakpointName {
7
+ Xs = "xs",
8
+ Sm = "sm",
9
+ Md = "md",
10
+ Lg = "lg",
11
+ Xl = "xl",
12
+ "2xl" = "2xl",
13
+ }
14
+
15
+ enum BreakpointWidth {
16
+ Xs = 0,
17
+ Sm = 640,
18
+ Md = 768,
19
+ Lg = 1024,
20
+ Xl = 1280,
21
+ "2xl" = 1536,
22
+ }
23
+
24
+ type Breakpoint = `${BreakpointName}`;
25
+
26
+ const mobileDevices = ["xs", "sm"];
27
+ const portableDevices = ["xs", "sm", "md"];
28
+
29
+ export default function useBreakpoint() {
30
+ let timeout: number | undefined;
31
+
32
+ const windowWidth = ref(0);
33
+ const currentBreakpoint: Ref<Breakpoint> = ref(BreakpointName.Xs);
34
+
35
+ const isMobileBreakpoint = computed(() => {
36
+ return mobileDevices.includes(currentBreakpoint.value);
37
+ });
38
+
39
+ const isTabletBreakpoint = computed(() => {
40
+ return mobileDevices.includes(currentBreakpoint.value);
41
+ });
42
+
43
+ const isLaptopBreakpoint = computed(() => {
44
+ return currentBreakpoint.value === BreakpointName.Lg;
45
+ });
46
+
47
+ const isPortableBreakpoint = computed(() => {
48
+ return portableDevices.includes(currentBreakpoint.value);
49
+ });
50
+
51
+ // TODO: Why do we need this? Maybe we should rename it.
52
+ const elementSize = computed(() => {
53
+ return isMobileBreakpoint.value ? BreakpointName.Md : BreakpointName.Lg;
54
+ });
55
+
56
+ onMounted(() => {
57
+ if (isSSR) return;
58
+
59
+ windowWidth.value = window.innerWidth;
60
+
61
+ window.addEventListener("resize", resizeListener, { passive: true });
62
+ });
63
+
64
+ onBeforeUnmount(() => {
65
+ if (isSSR) return;
66
+
67
+ window.removeEventListener("resize", resizeListener);
68
+ });
69
+
70
+ watch(windowWidth, setBreakpoint, { immediate: true });
71
+
72
+ function resizeListener() {
73
+ if (isSSR) return;
74
+
75
+ if (timeout) {
76
+ window.cancelAnimationFrame(timeout);
77
+ }
78
+
79
+ timeout = window.requestAnimationFrame(() => {
80
+ windowWidth.value = window.innerWidth;
81
+ });
82
+ }
83
+
84
+ function setBreakpoint(newWindowWidth: number) {
85
+ if (newWindowWidth === undefined) return;
86
+
87
+ currentBreakpoint.value = "xs";
88
+
89
+ if (newWindowWidth >= BreakpointWidth.Sm && newWindowWidth < BreakpointWidth.Sm) {
90
+ currentBreakpoint.value = BreakpointName.Sm;
91
+ } else if (newWindowWidth >= BreakpointWidth.Md && newWindowWidth < BreakpointWidth.Lg) {
92
+ currentBreakpoint.value = BreakpointName.Md;
93
+ } else if (newWindowWidth >= BreakpointWidth.Lg && newWindowWidth < BreakpointWidth.Xl) {
94
+ currentBreakpoint.value = BreakpointName.Lg;
95
+ } else if (newWindowWidth >= BreakpointWidth.Xl && newWindowWidth < BreakpointWidth["2xl"]) {
96
+ currentBreakpoint.value = BreakpointName.Xl;
97
+ } else if (newWindowWidth >= BreakpointWidth["2xl"]) {
98
+ currentBreakpoint.value = BreakpointName["2xl"];
99
+ }
100
+ }
101
+
102
+ return {
103
+ isLaptopBreakpoint,
104
+ isTabletBreakpoint,
105
+ isMobileBreakpoint,
106
+ isPortableBreakpoint,
107
+ elementSize,
108
+ };
109
+ }
@@ -0,0 +1,22 @@
1
+ import { inject } from "vue";
2
+ import createVuelessAdapter from "../adatper.locale/vueless.ts";
3
+
4
+ import type { LocaleInstance, LocaleOptions } from "../adatper.locale/vueless.ts";
5
+ import type { InjectionKey } from "vue";
6
+
7
+ export const LocaleSymbol: InjectionKey<LocaleInstance> = Symbol.for("vueless:locale");
8
+
9
+ export function createLocale(options?: LocaleOptions) {
10
+ const i18n =
11
+ options?.adapter && options?.adapter?.name ? options?.adapter : createVuelessAdapter(options);
12
+
13
+ return { ...i18n };
14
+ }
15
+
16
+ export function useLocale() {
17
+ const locale = inject(LocaleSymbol);
18
+
19
+ if (!locale) throw new Error("[vueless] Could not find injected locale instance");
20
+
21
+ return locale;
22
+ }
@@ -0,0 +1,53 @@
1
+ import { computed, onBeforeUnmount, onMounted, toValue, watch } from "vue";
2
+ import { isSSR } from "../utils/helper.ts";
3
+
4
+ import type { TemplateRefElement } from "../types.ts";
5
+
6
+ export function useMutationObserver(
7
+ target: TemplateRefElement,
8
+ callback: MutationCallback,
9
+ config = { childList: true, attributes: true, characterData: true },
10
+ ) {
11
+ if (isSSR) return;
12
+
13
+ const observer = new MutationObserver(callback);
14
+ const targetValue = computed(() => toValue(target));
15
+
16
+ onMounted(() => {
17
+ if (!targetValue.value) return;
18
+
19
+ if (Array.isArray(targetValue.value)) {
20
+ targetValue.value.forEach((element) => {
21
+ observer.observe(element, config);
22
+ });
23
+ } else {
24
+ observer.observe(targetValue.value, config);
25
+ }
26
+ });
27
+
28
+ watch(
29
+ targetValue,
30
+ () => {
31
+ if (!targetValue.value) return;
32
+
33
+ if (Array.isArray(targetValue.value)) {
34
+ targetValue.value.forEach((element) => {
35
+ observer.observe(element, config);
36
+ });
37
+
38
+ return;
39
+ }
40
+
41
+ observer.observe(targetValue.value, config);
42
+ },
43
+ {
44
+ deep: true,
45
+ },
46
+ );
47
+
48
+ onBeforeUnmount(() => {
49
+ observer.disconnect();
50
+ });
51
+
52
+ return { observer };
53
+ }