vueless 0.0.478-beta.2 → 0.0.478-beta.20

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 (312) hide show
  1. package/adatper.locale/vue-i18n.ts +14 -0
  2. package/adatper.locale/{vueless.js → vueless.ts} +67 -19
  3. package/{composablesTs → composables}/useAutoPosition.ts +35 -37
  4. package/{composablesTs → composables}/useBreakpoint.ts +37 -34
  5. package/composables/useLocale.ts +22 -0
  6. package/composables/useMutationObserver.ts +53 -0
  7. package/{composablesTs → composables}/useUI.ts +5 -226
  8. package/constants.js +123 -1
  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} +17 -5
  16. package/directives/tooltip/types.ts +14 -0
  17. package/directives/tooltip/vTooltip.ts +82 -0
  18. package/index.ts +5 -5
  19. package/package.json +12 -10
  20. package/preset.tailwind.js +5 -0
  21. package/types.ts +20 -5
  22. package/ui.button/UButton.vue +1 -1
  23. package/ui.button/config.js +0 -12
  24. package/ui.button/storybook/Docs.mdx +1 -1
  25. package/ui.button/storybook/stories.js +9 -4
  26. package/ui.button/useAttrs.js +1 -1
  27. package/ui.button-link/ULink.vue +1 -1
  28. package/ui.button-link/config.js +0 -9
  29. package/ui.button-link/storybook/Docs.mdx +1 -1
  30. package/ui.button-link/storybook/stories.js +1 -1
  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 +1 -1
  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 +1 -1
  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 +1 -1
  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 +1 -1
  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 +1 -1
  74. package/ui.container-row/useAttrs.js +1 -1
  75. package/ui.data-list/UDataList.vue +2 -2
  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/config.js +0 -1
  88. package/ui.dropdown-badge/storybook/Docs.mdx +1 -1
  89. package/ui.dropdown-badge/storybook/stories.js +1 -1
  90. package/ui.dropdown-badge/useAttrs.js +1 -1
  91. package/ui.dropdown-button/UDropdownButton.vue +1 -1
  92. package/ui.dropdown-button/config.js +0 -1
  93. package/ui.dropdown-button/storybook/Docs.mdx +1 -1
  94. package/ui.dropdown-button/storybook/stories.js +1 -1
  95. package/ui.dropdown-button/useAttrs.js +1 -1
  96. package/ui.dropdown-link/UDropdownLink.vue +1 -1
  97. package/ui.dropdown-link/config.js +1 -1
  98. package/ui.dropdown-link/storybook/Docs.mdx +1 -1
  99. package/ui.dropdown-link/storybook/stories.js +1 -1
  100. package/ui.dropdown-link/useAttrs.js +4 -6
  101. package/ui.dropdown-list/UDropdownList.vue +3 -3
  102. package/ui.dropdown-list/storybook/Docs.mdx +1 -1
  103. package/ui.dropdown-list/storybook/stories.js +1 -1
  104. package/ui.dropdown-list/useAttrs.js +1 -1
  105. package/ui.form-calendar/UCalendar.vue +2 -2
  106. package/ui.form-calendar/storybook/Docs.mdx +1 -1
  107. package/ui.form-calendar/storybook/stories.js +1 -1
  108. package/ui.form-calendar/useAttrs.js +1 -1
  109. package/ui.form-checkbox/UCheckbox.vue +1 -1
  110. package/ui.form-checkbox/config.js +0 -9
  111. package/ui.form-checkbox/storybook/Docs.mdx +1 -1
  112. package/ui.form-checkbox/storybook/stories.js +1 -1
  113. package/ui.form-checkbox/useAttrs.js +1 -1
  114. package/ui.form-checkbox-group/UCheckboxGroup.vue +1 -1
  115. package/ui.form-checkbox-group/storybook/Docs.mdx +1 -1
  116. package/ui.form-checkbox-group/storybook/stories.js +1 -1
  117. package/ui.form-checkbox-group/useAttrs.js +1 -1
  118. package/ui.form-checkbox-multi-state/UCheckboxMultiState.vue +1 -1
  119. package/ui.form-checkbox-multi-state/storybook/Docs.mdx +1 -1
  120. package/ui.form-checkbox-multi-state/storybook/stories.js +1 -1
  121. package/ui.form-checkbox-multi-state/useAttrs.js +1 -1
  122. package/ui.form-color-picker/UColorPicker.vue +1 -1
  123. package/ui.form-color-picker/config.js +0 -7
  124. package/ui.form-color-picker/storybook/Docs.mdx +1 -1
  125. package/ui.form-color-picker/storybook/stories.js +1 -1
  126. package/ui.form-color-picker/useAttrs.js +1 -1
  127. package/ui.form-date-picker/UDatePicker.vue +4 -7
  128. package/ui.form-date-picker/storybook/Docs.mdx +1 -1
  129. package/ui.form-date-picker/storybook/stories.js +1 -1
  130. package/ui.form-date-picker/useAttrs.js +2 -2
  131. package/ui.form-date-picker-range/UDatePickerRange.vue +2 -2
  132. package/ui.form-date-picker-range/storybook/Docs.mdx +1 -1
  133. package/ui.form-date-picker-range/storybook/stories.js +1 -1
  134. package/ui.form-date-picker-range/useAttrs.js +2 -2
  135. package/ui.form-date-picker-range/useLocale.js +1 -1
  136. package/ui.form-input/UInput.vue +2 -2
  137. package/ui.form-input/storybook/Docs.mdx +1 -1
  138. package/ui.form-input/storybook/stories.js +1 -1
  139. package/ui.form-input/useAttrs.js +1 -1
  140. package/ui.form-input-file/UInputFile.vue +2 -2
  141. package/ui.form-input-file/storybook/Docs.mdx +1 -1
  142. package/ui.form-input-file/storybook/stories.js +1 -1
  143. package/ui.form-input-file/useAttrs.js +1 -1
  144. package/ui.form-input-money/UInputMoney.vue +1 -1
  145. package/ui.form-input-money/storybook/Docs.mdx +1 -1
  146. package/ui.form-input-money/storybook/stories.js +1 -1
  147. package/ui.form-input-money/useAttrs.js +1 -1
  148. package/ui.form-input-number/UInputNumber.vue +1 -1
  149. package/ui.form-input-number/storybook/Docs.mdx +1 -1
  150. package/ui.form-input-number/storybook/stories.js +1 -1
  151. package/ui.form-input-number/useAttrs.js +1 -1
  152. package/ui.form-input-rating/UInputRating.vue +1 -1
  153. package/ui.form-input-rating/storybook/Docs.mdx +1 -1
  154. package/ui.form-input-rating/storybook/stories.js +1 -1
  155. package/ui.form-input-rating/useAttrs.js +1 -1
  156. package/ui.form-input-search/UInputSearch.vue +2 -2
  157. package/ui.form-input-search/storybook/Docs.mdx +1 -1
  158. package/ui.form-input-search/storybook/stories.js +1 -1
  159. package/ui.form-input-search/useAttrs.js +1 -1
  160. package/ui.form-label/ULabel.vue +1 -1
  161. package/ui.form-label/storybook/Docs.mdx +1 -1
  162. package/ui.form-label/storybook/stories.js +1 -1
  163. package/ui.form-label/useAttrs.js +1 -1
  164. package/ui.form-radio/URadio.vue +1 -1
  165. package/ui.form-radio/config.js +0 -6
  166. package/ui.form-radio/storybook/Docs.mdx +1 -1
  167. package/ui.form-radio/storybook/stories.js +1 -1
  168. package/ui.form-radio/useAttrs.js +1 -1
  169. package/ui.form-radio-group/URadioGroup.vue +1 -1
  170. package/ui.form-radio-group/storybook/Docs.mdx +1 -1
  171. package/ui.form-radio-group/storybook/stories.js +1 -1
  172. package/ui.form-radio-group/useAttrs.js +1 -1
  173. package/ui.form-select/USelect.vue +4 -4
  174. package/ui.form-select/storybook/Docs.mdx +1 -1
  175. package/ui.form-select/storybook/stories.js +1 -1
  176. package/ui.form-select/useAttrs.js +1 -1
  177. package/ui.form-switch/USwitch.vue +2 -2
  178. package/ui.form-switch/config.js +0 -6
  179. package/ui.form-switch/storybook/Docs.mdx +1 -1
  180. package/ui.form-switch/storybook/stories.js +1 -1
  181. package/ui.form-switch/useAttrs.js +1 -1
  182. package/ui.form-switch/utilVariant.js +1 -1
  183. package/ui.form-textarea/UTextarea.vue +1 -1
  184. package/ui.form-textarea/storybook/Docs.mdx +1 -1
  185. package/ui.form-textarea/storybook/stories.js +1 -1
  186. package/ui.form-textarea/useAttrs.js +1 -1
  187. package/ui.image-avatar/UAvatar.vue +1 -1
  188. package/ui.image-avatar/config.js +0 -5
  189. package/ui.image-avatar/storybook/Docs.mdx +1 -1
  190. package/ui.image-avatar/storybook/stories.js +1 -1
  191. package/ui.image-avatar/useAttrs.js +1 -1
  192. package/ui.image-icon/UIcon.vue +23 -8
  193. package/ui.image-icon/{config.js → config.ts} +0 -5
  194. package/ui.image-icon/storybook/Docs.mdx +2 -2
  195. package/ui.image-icon/storybook/stories.js +1 -1
  196. package/ui.image-icon/useAttrs.js +2 -2
  197. package/ui.loader/ULoader.vue +1 -1
  198. package/ui.loader/config.js +0 -1
  199. package/ui.loader/storybook/Docs.mdx +1 -1
  200. package/ui.loader/storybook/stories.js +1 -1
  201. package/ui.loader/useAttrs.js +1 -1
  202. package/ui.loader-overlay/ULoaderOverlay.vue +1 -1
  203. package/ui.loader-overlay/config.js +0 -1
  204. package/ui.loader-overlay/storybook/Docs.mdx +1 -1
  205. package/ui.loader-overlay/storybook/stories.js +1 -1
  206. package/ui.loader-overlay/useAttrs.js +1 -1
  207. package/ui.loader-progress/ULoaderProgress.vue +33 -48
  208. package/ui.loader-progress/config.js +0 -1
  209. package/ui.loader-progress/constants.js +1 -0
  210. package/ui.loader-progress/storybook/Docs.mdx +1 -1
  211. package/ui.loader-progress/storybook/stories.js +2 -3
  212. package/ui.loader-progress/useAttrs.js +1 -1
  213. package/ui.loader-progress/useLoaderProgress.js +13 -8
  214. package/ui.loader-progress/utilLoaderProgress.js +1 -1
  215. package/ui.navigation-pagination/UPagination.vue +1 -1
  216. package/ui.navigation-pagination/storybook/Docs.mdx +1 -1
  217. package/ui.navigation-pagination/storybook/stories.js +1 -1
  218. package/ui.navigation-pagination/useAttrs.js +1 -1
  219. package/ui.navigation-progress/UProgress.vue +1 -1
  220. package/ui.navigation-progress/config.js +0 -9
  221. package/ui.navigation-progress/storybook/Docs.mdx +1 -1
  222. package/ui.navigation-progress/storybook/stories.js +1 -1
  223. package/ui.navigation-progress/useAttrs.js +1 -1
  224. package/ui.navigation-tab/UTab.vue +1 -1
  225. package/ui.navigation-tab/storybook/Docs.mdx +1 -1
  226. package/ui.navigation-tab/storybook/stories.js +1 -1
  227. package/ui.navigation-tab/useAttrs.js +1 -1
  228. package/ui.navigation-tabs/UTabs.vue +1 -1
  229. package/ui.navigation-tabs/storybook/Docs.mdx +1 -1
  230. package/ui.navigation-tabs/storybook/stories.js +1 -1
  231. package/ui.navigation-tabs/useAttrs.js +1 -1
  232. package/ui.other-dot/UDot.vue +1 -1
  233. package/ui.other-dot/config.js +0 -1
  234. package/ui.other-dot/storybook/Docs.mdx +1 -1
  235. package/ui.other-dot/storybook/stories.js +1 -1
  236. package/ui.other-dot/useAttrs.js +1 -1
  237. package/ui.text-alert/UAlert.vue +1 -1
  238. package/ui.text-alert/config.js +0 -7
  239. package/ui.text-alert/storybook/Docs.mdx +1 -1
  240. package/ui.text-alert/storybook/stories.js +1 -1
  241. package/ui.text-alert/useAttrs.js +1 -1
  242. package/ui.text-badge/UBadge.vue +89 -179
  243. package/ui.text-badge/{config.js → config.ts} +0 -8
  244. package/ui.text-badge/storybook/Docs.mdx +3 -3
  245. package/ui.text-badge/storybook/{stories.js → stories.ts} +26 -35
  246. package/ui.text-badge/types.ts +84 -0
  247. package/ui.text-badge/useAttrs.ts +28 -0
  248. package/ui.text-block/UText.vue +1 -1
  249. package/ui.text-block/storybook/Docs.mdx +1 -1
  250. package/ui.text-block/storybook/stories.ts +1 -1
  251. package/ui.text-block/useAttrs.ts +1 -1
  252. package/ui.text-empty/UEmpty.vue +1 -1
  253. package/ui.text-empty/storybook/Docs.mdx +1 -1
  254. package/ui.text-empty/storybook/stories.js +1 -1
  255. package/ui.text-empty/useAttrs.js +1 -1
  256. package/ui.text-file/UFile.vue +1 -2
  257. package/ui.text-file/storybook/Docs.mdx +1 -1
  258. package/ui.text-file/storybook/stories.js +1 -1
  259. package/ui.text-file/useAttrs.js +1 -1
  260. package/ui.text-files/UFiles.vue +1 -1
  261. package/ui.text-files/storybook/Docs.mdx +1 -1
  262. package/ui.text-files/storybook/stories.js +1 -1
  263. package/ui.text-files/useAttrs.js +1 -1
  264. package/ui.text-header/UHeader.vue +1 -1
  265. package/ui.text-header/config.js +0 -1
  266. package/ui.text-header/storybook/Docs.mdx +1 -1
  267. package/ui.text-header/storybook/stories.js +1 -1
  268. package/ui.text-header/useAttrs.js +1 -1
  269. package/ui.text-money/UMoney.vue +1 -1
  270. package/ui.text-money/config.js +0 -1
  271. package/ui.text-money/storybook/Docs.mdx +1 -1
  272. package/ui.text-money/storybook/stories.js +1 -1
  273. package/ui.text-money/useAttrs.js +1 -1
  274. package/ui.text-notify/UNotify.vue +2 -2
  275. package/ui.text-notify/storybook/Docs.mdx +1 -1
  276. package/ui.text-notify/storybook/stories.js +1 -1
  277. package/ui.text-notify/useAttrs.js +1 -1
  278. package/ui.text-notify/utilNotify.js +1 -1
  279. package/utils/node/helper.js +107 -0
  280. package/utils/node/loaderIcon.js +232 -0
  281. package/utils/node/loaderSvg.js +71 -0
  282. package/utils/node/mergeConfigs.js +199 -0
  283. package/utils/node/tailwindSafelist.js +362 -0
  284. package/utils/node/vuelessConfig.js +40 -0
  285. package/utils/node/vuelessResolver.js +28 -0
  286. package/{utilsTs/utilPlatform.ts → utils/platform.ts} +1 -1
  287. package/{utilsTs/utilStorybook.ts → utils/storybook.ts} +48 -25
  288. package/{utilsTs/utilTailwind.ts → utils/tailwindConfig.ts} +7 -12
  289. package/{utilsTs/utilTheme.ts → utils/theme.ts} +40 -16
  290. package/{utilsTs/utilUI.ts → utils/ui.ts} +7 -21
  291. package/vite.d.ts +10 -0
  292. package/vite.js +100 -0
  293. package/web-types.json +1362 -157
  294. package/adatper.locale/vue-i18n.js +0 -11
  295. package/composables/useAutoPosition.js +0 -94
  296. package/composables/useBreakpoint.js +0 -104
  297. package/composables/useLocale.js +0 -25
  298. package/composables/useMutationObserver.js +0 -48
  299. package/composables/useUI.js +0 -535
  300. package/composablesTs/useLocale.ts +0 -25
  301. package/composablesTs/useMutationObserver.ts +0 -50
  302. package/constants.ts +0 -73
  303. package/directives/clickOutside/vClickOutside.js +0 -64
  304. package/directives/tooltip/vTooltip.js +0 -56
  305. package/ui.text-badge/useAttrs.js +0 -23
  306. package/utils/utilHelper.js +0 -81
  307. package/utils/utilPlatform.js +0 -46
  308. package/utils/utilStorybook.js +0 -191
  309. package/utils/utilUI.js +0 -156
  310. /package/adatper.locale/locales/{en.js → en.ts} +0 -0
  311. /package/ui.text-badge/{constants.js → constants.ts} +0 -0
  312. /package/{utilsTs/utilHelper.ts → utils/helper.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
  }
@@ -1,14 +1,9 @@
1
1
  import { computed, toValue, ref } from "vue";
2
- import { isSSR } from "../utilsTs/utilHelper.ts";
2
+ import { isSSR } from "../utils/helper.ts";
3
3
 
4
- import type { Ref, ComputedRef } from "vue";
4
+ import type { ComputedRef, MaybeRef, Reactive } from "vue";
5
5
 
6
- interface PositionXY {
7
- x: Position;
8
- y: Position;
9
- }
10
-
11
- export enum Position {
6
+ export enum Direction {
12
7
  Left = "left",
13
8
  Right = "right",
14
9
  Top = "top",
@@ -16,7 +11,10 @@ export enum Position {
16
11
  Auto = "auto",
17
12
  }
18
13
 
19
- // TODO: Remove after full TS migration, use enum instead.
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).
20
18
  export const POSITION = {
21
19
  left: "left",
22
20
  right: "right",
@@ -26,52 +24,52 @@ export const POSITION = {
26
24
  };
27
25
 
28
26
  export function useAutoPosition(
29
- anchorElement: Ref<HTMLElement | null>,
30
- targetElement: Ref<HTMLElement | null>,
31
- position: PositionXY | ComputedRef<PositionXY>,
32
- preferredPosition: PositionXY | ComputedRef<PositionXY>,
27
+ anchorElement: MaybeRef<HTMLElement | null>,
28
+ targetElement: MaybeRef<HTMLElement | null>,
29
+ position: Reactive<Position> | ComputedRef<Position>,
30
+ preferredPosition: Reactive<Position> | ComputedRef<Position>,
33
31
  ) {
34
32
  const localAnchorElement = computed(() => toValue(anchorElement));
35
33
  const localTargetElement = computed(() => toValue(targetElement));
36
34
  const localPosition = computed(() => toValue(position));
37
35
  const localPreferredPosition = computed(() => toValue(preferredPosition));
38
36
 
39
- const preferredOpenDirectionY = ref(localPreferredPosition.value?.y || Position.Bottom);
40
- const preferredOpenDirectionX = ref(localPreferredPosition.value?.x || Position.Left);
37
+ const preferredOpenDirectionY = ref(localPreferredPosition.value.y || Direction.Bottom);
38
+ const preferredOpenDirectionX = ref(localPreferredPosition.value.x || Direction.Left);
41
39
 
42
40
  const isTop = computed(() => {
43
- if (localPosition.value.y !== Position.Auto) {
44
- return localPosition.value.y === Position.Top;
41
+ if (localPosition.value.y !== Direction.Auto) {
42
+ return localPosition.value.y === Direction.Top;
45
43
  }
46
44
 
47
- return preferredOpenDirectionY.value === Position.Top;
45
+ return preferredOpenDirectionY.value === Direction.Top;
48
46
  });
49
47
 
50
48
  const isLeft = computed(() => {
51
- if (localPosition.value.x !== Position.Auto) {
52
- return localPosition.value.x === Position.Left;
49
+ if (localPosition.value.x !== Direction.Auto) {
50
+ return localPosition.value.x === Direction.Left;
53
51
  }
54
52
 
55
- return preferredOpenDirectionX.value === Position.Left;
53
+ return preferredOpenDirectionX.value === Direction.Left;
56
54
  });
57
55
 
58
56
  const isBottom = computed(() => {
59
- if (localPosition.value.y !== Position.Auto) {
60
- return localPosition.value.y === Position.Bottom;
57
+ if (localPosition.value.y !== Direction.Auto) {
58
+ return localPosition.value.y === Direction.Bottom;
61
59
  }
62
60
 
63
- return preferredOpenDirectionY.value === Position.Bottom;
61
+ return preferredOpenDirectionY.value === Direction.Bottom;
64
62
  });
65
63
 
66
64
  const isRight = computed(() => {
67
- if (localPosition.value.x !== Position.Auto) {
68
- return localPosition.value.x === Position.Right;
65
+ if (localPosition.value.x !== Direction.Auto) {
66
+ return localPosition.value.x === Direction.Right;
69
67
  }
70
68
 
71
- return preferredOpenDirectionX.value === Position.Right;
69
+ return preferredOpenDirectionX.value === Direction.Right;
72
70
  });
73
71
 
74
- function adjustPositionY(): void {
72
+ function adjustPositionY() {
75
73
  if (isSSR || !localAnchorElement.value || !localTargetElement.value) return;
76
74
 
77
75
  const spaceAbove = localAnchorElement.value.getBoundingClientRect().top;
@@ -81,18 +79,18 @@ export function useAutoPosition(
81
79
  const hasEnoughSpaceAbove =
82
80
  spaceAbove > localTargetElement.value.getBoundingClientRect().height;
83
81
 
84
- if (localPreferredPosition.value.y === Position.Bottom) {
82
+ if (localPreferredPosition.value.y === Direction.Bottom) {
85
83
  preferredOpenDirectionY.value =
86
- hasEnoughSpaceBelow || spaceBelow > spaceAbove ? Position.Bottom : Position.Top;
84
+ hasEnoughSpaceBelow || spaceBelow > spaceAbove ? Direction.Bottom : Direction.Top;
87
85
  }
88
86
 
89
- if (localPreferredPosition.value.y === Position.Top) {
87
+ if (localPreferredPosition.value.y === Direction.Top) {
90
88
  preferredOpenDirectionY.value =
91
- hasEnoughSpaceAbove || spaceAbove > spaceBelow ? Position.Top : Position.Bottom;
89
+ hasEnoughSpaceAbove || spaceAbove > spaceBelow ? Direction.Top : Direction.Bottom;
92
90
  }
93
91
  }
94
92
 
95
- function adjustPositionX(): void {
93
+ function adjustPositionX() {
96
94
  if (isSSR || !localAnchorElement.value || !localTargetElement.value) return;
97
95
 
98
96
  const spaceRight = localAnchorElement.value.getBoundingClientRect().right;
@@ -100,14 +98,14 @@ export function useAutoPosition(
100
98
  const hasEnoughSpaceLeft = spaceLeft > localTargetElement.value.getBoundingClientRect().width;
101
99
  const hasEnoughSpaceRight = spaceRight > localTargetElement.value.getBoundingClientRect().width;
102
100
 
103
- if (localPreferredPosition.value.x === Position.Right) {
101
+ if (localPreferredPosition.value.x === Direction.Right) {
104
102
  preferredOpenDirectionX.value =
105
- hasEnoughSpaceRight || spaceRight > spaceLeft ? Position.Right : Position.Left;
103
+ hasEnoughSpaceRight || spaceRight > spaceLeft ? Direction.Right : Direction.Left;
106
104
  }
107
105
 
108
- if (localPreferredPosition.value.x === Position.Left) {
106
+ if (localPreferredPosition.value.x === Direction.Left) {
109
107
  preferredOpenDirectionX.value =
110
- hasEnoughSpaceLeft || spaceLeft > spaceRight ? Position.Left : Position.Right;
108
+ hasEnoughSpaceLeft || spaceLeft > spaceRight ? Direction.Left : Direction.Right;
111
109
  }
112
110
  }
113
111
 
@@ -1,34 +1,36 @@
1
1
  import { onMounted, ref, watch, computed, onBeforeUnmount } from "vue";
2
- import { isSSR } from "../utilsTs/utilHelper.ts";
2
+ import { isSSR } from "../utils/helper.ts";
3
3
 
4
4
  import type { Ref } from "vue";
5
5
 
6
- const BREAKPOINT_NAME = {
7
- xs: "xs",
8
- sm: "sm",
9
- md: "md",
10
- lg: "lg",
11
- xl: "xl",
12
- "2xl": "2xl",
13
- };
14
-
15
- const BREAKPOINT = {
16
- xs: 0,
17
- sm: 640,
18
- md: 768,
19
- lg: 1024,
20
- xl: 1280,
21
- "2xl": 1536,
22
- };
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}`;
23
25
 
24
26
  const mobileDevices = ["xs", "sm"];
25
27
  const portableDevices = ["xs", "sm", "md"];
26
28
 
27
29
  export default function useBreakpoint() {
28
- let timeout: number;
30
+ let timeout: number | undefined;
29
31
 
30
- const windowWidth: Ref<number | undefined> = ref(undefined);
31
- const currentBreakpoint = ref(BREAKPOINT_NAME.xs);
32
+ const windowWidth = ref(0);
33
+ const currentBreakpoint: Ref<Breakpoint> = ref(BreakpointName.Xs);
32
34
 
33
35
  const isMobileBreakpoint = computed(() => {
34
36
  return mobileDevices.includes(currentBreakpoint.value);
@@ -39,15 +41,16 @@ export default function useBreakpoint() {
39
41
  });
40
42
 
41
43
  const isLaptopBreakpoint = computed(() => {
42
- return currentBreakpoint.value === BREAKPOINT_NAME.lg;
44
+ return currentBreakpoint.value === BreakpointName.Lg;
43
45
  });
44
46
 
45
47
  const isPortableBreakpoint = computed(() => {
46
48
  return portableDevices.includes(currentBreakpoint.value);
47
49
  });
48
50
 
51
+ // TODO: Why do we need this? Maybe we should rename it.
49
52
  const elementSize = computed(() => {
50
- return isMobileBreakpoint.value ? BREAKPOINT_NAME.md : BREAKPOINT_NAME.lg;
53
+ return isMobileBreakpoint.value ? BreakpointName.Md : BreakpointName.Lg;
51
54
  });
52
55
 
53
56
  onMounted(() => {
@@ -78,21 +81,21 @@ export default function useBreakpoint() {
78
81
  });
79
82
  }
80
83
 
81
- function setBreakpoint(newWindowWidth: number | undefined) {
84
+ function setBreakpoint(newWindowWidth: number) {
82
85
  if (newWindowWidth === undefined) return;
83
86
 
84
87
  currentBreakpoint.value = "xs";
85
88
 
86
- if (newWindowWidth >= BREAKPOINT.sm && newWindowWidth < BREAKPOINT.md) {
87
- currentBreakpoint.value = "sm";
88
- } else if (newWindowWidth >= BREAKPOINT.md && newWindowWidth < BREAKPOINT.lg) {
89
- currentBreakpoint.value = "md";
90
- } else if (newWindowWidth >= BREAKPOINT.lg && newWindowWidth < BREAKPOINT.xl) {
91
- currentBreakpoint.value = "lg";
92
- } else if (newWindowWidth >= BREAKPOINT.xl && newWindowWidth < BREAKPOINT["2xl"]) {
93
- currentBreakpoint.value = "xl";
94
- } else if (newWindowWidth >= BREAKPOINT["2xl"]) {
95
- currentBreakpoint.value = "2xl";
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"];
96
99
  }
97
100
  }
98
101
 
@@ -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
+ }