@basmilius/common 3.0.2 → 3.1.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@basmilius/common",
3
3
  "description": "Common code shared in personal projects.",
4
- "version": "3.0.2",
4
+ "version": "3.1.0",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/basmilius",
@@ -48,8 +48,8 @@
48
48
  "./*": "./*"
49
49
  },
50
50
  "dependencies": {
51
- "@basmilius/http-client": "3.0.2",
52
- "@basmilius/utils": "3.0.2",
51
+ "@basmilius/http-client": "3.1.0",
52
+ "@basmilius/utils": "3.1.0",
53
53
  "@flux-ui/components": "^3.0.0-next.26",
54
54
  "@flux-ui/internals": "^3.0.0-next.26",
55
55
  "pinia": "^3.0.4",
@@ -57,7 +57,7 @@
57
57
  "vue-router": "^5.0.3"
58
58
  },
59
59
  "devDependencies": {
60
- "@basmilius/tools": "3.0.2",
60
+ "@basmilius/tools": "3.1.0",
61
61
  "@types/culori": "^4.0.1",
62
62
  "@types/lodash-es": "^4.17.12",
63
63
  "culori": "^4.0.2",
@@ -2,6 +2,7 @@ export { default as useCopy } from './useCopy';
2
2
  export { default as useDebounced } from './useDebounced';
3
3
  export { default as useDtoForm } from './useDtoForm';
4
4
  export { default as useInterval } from './useInterval';
5
+ export { default as useIsView } from './useIsView';
5
6
  export { default as useLoaded } from './useLoaded';
6
7
  export { default as useLoadedAction } from './useLoadedAction';
7
8
  export { default as useLocalFile } from './useLocalFile';
@@ -1,8 +1,10 @@
1
1
  import { type Ref, unref } from 'vue';
2
2
 
3
- export default function (contents: Ref<string>, onSuccess?: Function) {
3
+ export default function (contents: Ref<string>, onSuccess?: Function): UseCopy {
4
4
  return async () => {
5
5
  await navigator.clipboard.writeText(unref(contents));
6
6
  onSuccess?.();
7
7
  };
8
8
  }
9
+
10
+ type UseCopy = () => Promise<void>;
@@ -1,8 +1,8 @@
1
1
  import { cloneDto, markDtoClean } from '@basmilius/http-client';
2
2
  import { ref, type Ref, watch } from 'vue';
3
3
 
4
- export default function <T>(dtoRef: Ref<T | null>) {
5
- const form = ref<T>();
4
+ export default function <T>(dtoRef: Ref<T | null>): Ref<T> {
5
+ const form = ref<T>() as Ref<T>;
6
6
 
7
7
  watch(dtoRef, dto => {
8
8
  if (!dto) {
@@ -0,0 +1,12 @@
1
+ import { computed, unref } from 'vue';
2
+ import useRouteNames from './useRouteNames';
3
+
4
+ export default function (name: string, loose: boolean = false) {
5
+ const names = useRouteNames();
6
+
7
+ if (loose) {
8
+ return computed(() => unref(names).some(n => n.startsWith(name)));
9
+ }
10
+
11
+ return computed(() => unref(names).some(n => n === name));
12
+ }
@@ -1,6 +1,6 @@
1
- import { ref, watch } from 'vue';
1
+ import { type Ref, ref, watch } from 'vue';
2
2
 
3
- export default function () {
3
+ export default function (): UseLocalFile {
4
4
  const file = ref<File | null>(null);
5
5
  const url = ref<string | null>(null);
6
6
 
@@ -38,3 +38,11 @@ export default function () {
38
38
  upload: uploadFile
39
39
  };
40
40
  }
41
+
42
+ type UseLocalFile = {
43
+ readonly file: Ref<File | null>;
44
+ readonly url: Ref<string | null>;
45
+
46
+ delete: () => void;
47
+ upload: (uploadedFile: File) => void;
48
+ };
@@ -1,7 +1,7 @@
1
- import { computed, provide, type Ref, unref } from 'vue';
2
- import { useRoute, viewDepthKey } from 'vue-router';
1
+ import { computed, type ComputedRef, provide, type Ref, unref } from 'vue';
2
+ import { type RouteLocationNormalizedLoadedGeneric, useRoute, viewDepthKey } from 'vue-router';
3
3
 
4
- export default function (nameRef: Ref<string> | string) {
4
+ export default function (nameRef: Ref<string> | string): UseNamedRoute {
5
5
  const route = useRoute();
6
6
 
7
7
  const depth = computed(() => route.matched.findIndex(m => !!m.components && unref(nameRef) in m.components));
@@ -15,3 +15,8 @@ export default function (nameRef: Ref<string> | string) {
15
15
  viewKey
16
16
  };
17
17
  }
18
+
19
+ type UseNamedRoute = {
20
+ readonly route: RouteLocationNormalizedLoadedGeneric;
21
+ readonly viewKey: ComputedRef<string | undefined>;
22
+ };
@@ -1,10 +1,11 @@
1
1
  import { type NavigationFailure, type RouteLocationRaw, useRouter } from 'vue-router';
2
2
 
3
+ type Result = NavigationFailure | void | undefined;
3
4
  type To = Omit<RouteLocationRaw, 'replace'>;
4
- type Navigate = (to: To, replace?: boolean) => Promise<NavigationFailure | void | undefined>;
5
+ type Navigate = (to: To, replace?: boolean) => Promise<Result>;
5
6
  type Wrap = (fn: Navigate) => Navigate;
6
7
 
7
- export default function (...wrap: Wrap[]) {
8
+ export default function (...wrap: Wrap[]): UseNavigate {
8
9
  const router = useRouter();
9
10
 
10
11
  let navigate = async (to: To, replace: boolean = false) => {
@@ -26,3 +27,9 @@ export default function (...wrap: Wrap[]) {
26
27
  replace: (to: To) => navigate(to, true)
27
28
  };
28
29
  }
30
+
31
+ type UseNavigate = {
32
+ navigate(to: To, replace?: boolean): Promise<Result>;
33
+ push(to: To): Promise<Result>;
34
+ replace(to: To): Promise<Result>;
35
+ };
@@ -1,10 +1,10 @@
1
- import { ref } from 'vue';
1
+ import { ref, type Ref } from 'vue';
2
2
 
3
3
  const DEFAULT_LIMITS = [5, 10, 25, 50, 100];
4
4
  const DEFAULT_PAGE = 1;
5
5
  const DEFAULT_PER_PAGE = 25;
6
6
 
7
- export default function () {
7
+ export default function (): UsePagination {
8
8
  const limits = ref(DEFAULT_LIMITS);
9
9
  const page = ref(DEFAULT_PAGE);
10
10
  const perPage = ref(DEFAULT_PER_PAGE);
@@ -33,3 +33,14 @@ export default function () {
33
33
  setTotal
34
34
  };
35
35
  };
36
+
37
+ type UsePagination = {
38
+ readonly limits: Ref<number[]>;
39
+ readonly page: Ref<number>;
40
+ readonly perPage: Ref<number>;
41
+ readonly total: Ref<number>;
42
+
43
+ setPage(num: number): void;
44
+ setPerPage(num: number): void;
45
+ setTotal(num: number): void;
46
+ };
@@ -1,4 +1,4 @@
1
- import { computed, type Ref, unref } from 'vue';
1
+ import { computed, type ComputedRef, type Ref, unref } from 'vue';
2
2
 
3
3
  type PasswordRuleType =
4
4
  | 'lowercase'
@@ -44,7 +44,7 @@ const rules: PasswordRule[] = [
44
44
  {regex: new RegExp('[!"#\$%&\'\(\)\*\+,-\./:;<=>\?@\[\\\\\\]\^_`\{|\}~]'), type: 'symbol'}
45
45
  ];
46
46
 
47
- export default function (passwordRef: Ref<string>) {
47
+ export default function (passwordRef: Ref<string>): ComputedRef<Result | null> {
48
48
  return computed<Result | null>(() => {
49
49
  const password = unref(passwordRef);
50
50
 
@@ -2,7 +2,7 @@ import { merge } from 'lodash-es';
2
2
  import { computed, type Ref } from 'vue';
3
3
  import { useRoute } from 'vue-router';
4
4
 
5
- type RouteMeta = {
5
+ type RouteMeta = Record<string, unknown> & {
6
6
  readonly name?: string;
7
7
  };
8
8
 
@@ -1,7 +1,7 @@
1
- import { computed } from 'vue';
1
+ import { computed, type ComputedRef } from 'vue';
2
2
  import { useRoute } from 'vue-router';
3
3
 
4
- export default function () {
4
+ export default function (): ComputedRef<string[]> {
5
5
  const route = useRoute();
6
6
 
7
7
  return computed(() => {