1
0
mirror of https://github.com/robonen/tools.git synced 2026-03-20 19:04:46 +00:00

chore(packages/vue): update jsdoc, fill package.json

This commit is contained in:
2024-10-23 07:48:40 +07:00
parent b6d5b5b92c
commit c350c977d5
19 changed files with 66 additions and 6 deletions

View File

@@ -1,10 +1,15 @@
{ {
"name": "@robonen/vue", "name": "@robonen/vue",
"private": true, "version": "0.0.1",
"version": "0.0.0", "license": "Apache-2.0",
"license": "UNLICENSED", "description": "Collection of powerful tools for Vue",
"description": "", "keywords": [
"keywords": [], "vue",
"tools",
"ui",
"utilities",
"composables"
],
"author": "Robonen Andrew <robonenandrew@gmail.com>", "author": "Robonen Andrew <robonenandrew@gmail.com>",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@@ -25,6 +25,8 @@ export interface TryOnBeforeMountOptions {
* *
* @example * @example
* tryOnBeforeMount(() => console.log('Before mount async'), { sync: false }); * tryOnBeforeMount(() => console.log('Before mount async'), { sync: false });
*
* @since 0.0.1
*/ */
export function tryOnBeforeMount(fn: VoidFunction, options: TryOnBeforeMountOptions = {}) { export function tryOnBeforeMount(fn: VoidFunction, options: TryOnBeforeMountOptions = {}) {
const { const {

View File

@@ -25,6 +25,8 @@ export interface TryOnMountedOptions {
* *
* @example * @example
* tryOnMounted(() => console.log('Mounted!'), { sync: false }); * tryOnMounted(() => console.log('Mounted!'), { sync: false });
*
* @since 0.0.1
*/ */
export function tryOnMounted(fn: VoidFunction, options: TryOnMountedOptions = {}) { export function tryOnMounted(fn: VoidFunction, options: TryOnMountedOptions = {}) {
const { const {

View File

@@ -14,6 +14,7 @@ const ComponentStub = defineComponent({
setup(props) { setup(props) {
tryOnScopeDispose(props.callback); tryOnScopeDispose(props.callback);
}, },
template: '<div></div>',
}); });
describe('tryOnScopeDispose', () => { describe('tryOnScopeDispose', () => {

View File

@@ -11,6 +11,8 @@ import { getCurrentScope, onScopeDispose } from 'vue';
* *
* @example * @example
* tryOnScopeDispose(() => console.log('Scope disposed')); * tryOnScopeDispose(() => console.log('Scope disposed'));
*
* @since 0.0.1
*/ */
export function tryOnScopeDispose(callback: VoidFunction) { export function tryOnScopeDispose(callback: VoidFunction) {
if (getCurrentScope()) { if (getCurrentScope()) {

View File

@@ -23,6 +23,8 @@ import { effectScope } from 'vue';
* const increment = () => state.count++; * const increment = () => state.count++;
* return { state, increment }; * return { state, increment };
* }); * });
*
* @since 0.0.1
*/ */
export function useAppSharedState<Fn extends AnyFunction>(stateFactory: Fn) { export function useAppSharedState<Fn extends AnyFunction>(stateFactory: Fn) {
let initialized = false; let initialized = false;

View File

@@ -19,6 +19,8 @@ export type Comparator<Value> = (a: Value, b: Value) => boolean;
* @example * @example
* const externalValue = ref(0); * const externalValue = ref(0);
* const cachedValue = useCached(externalValue, (a, b) => a === b, { immediate: true }); * const cachedValue = useCached(externalValue, (a, b) => a === b, { immediate: true });
*
* @since 0.0.1
*/ */
export function useCached<Value = unknown>( export function useCached<Value = unknown>(
externalValue: MaybeRefOrGetter<Value>, externalValue: MaybeRefOrGetter<Value>,

View File

@@ -18,6 +18,8 @@ import { computed, isReadonly, ref, toValue, type ComputedRef, type MaybeRef, ty
* @example * @example
* const value = ref(10); * const value = ref(10);
* const clampedValue = useClamp(value, () => 0, () => 5); * const clampedValue = useClamp(value, () => 0, () => 5);
*
* @since 0.0.1
*/ */
export function useClamp(value: MaybeRef<number>, min: MaybeRefOrGetter<number>, max: MaybeRefOrGetter<number>): WritableComputedRef<number>; export function useClamp(value: MaybeRef<number>, min: MaybeRefOrGetter<number>, max: MaybeRefOrGetter<number>): WritableComputedRef<number>;
export function useClamp(value: MaybeRefOrGetter<number>, min: MaybeRefOrGetter<number>, max: MaybeRefOrGetter<number>): ComputedRef<number> { export function useClamp(value: MaybeRefOrGetter<number>, min: MaybeRefOrGetter<number>, max: MaybeRefOrGetter<number>): ComputedRef<number> {

View File

@@ -12,6 +12,8 @@ import { VueToolsError } from '../..';
* *
* @example * @example
* const [injectContext, provideContext] = useContextFactory('MyContext'); * const [injectContext, provideContext] = useContextFactory('MyContext');
*
* @since 0.0.1
*/ */
export function useContextFactory<ContextValue>(name: string) { export function useContextFactory<ContextValue>(name: string) {
const injectionKey: InjectionKey<ContextValue> = Symbol(name); const injectionKey: InjectionKey<ContextValue> = Symbol(name);

View File

@@ -31,6 +31,8 @@ export interface UseConterReturn {
* *
* @example * @example
* const { count, increment, decrement, set, get, reset } = useCounter(0, { min: 0, max: 10 }); * const { count, increment, decrement, set, get, reset } = useCounter(0, { min: 0, max: 10 });
*
* @since 0.0.1
*/ */
export function useCounter( export function useCounter(
initialValue: MaybeRefOrGetter<number> = 0, initialValue: MaybeRefOrGetter<number> = 0,

View File

@@ -24,6 +24,8 @@ export interface UseLastChangedOptions<
* @example * @example
* const value = ref(0); * const value = ref(0);
* const lastChanged = useLastChanged(value, { immediate: true }); * const lastChanged = useLastChanged(value, { immediate: true });
*
* @since 0.0.1
*/ */
export function useLastChanged(source: WatchSource, options?: UseLastChangedOptions<false>): Ref<number | null>; export function useLastChanged(source: WatchSource, options?: UseLastChangedOptions<false>): Ref<number | null>;
export function useLastChanged(source: WatchSource, options: UseLastChangedOptions<true> | UseLastChangedOptions<boolean, number>): Ref<number> export function useLastChanged(source: WatchSource, options: UseLastChangedOptions<true> | UseLastChangedOptions<boolean, number>): Ref<number>

View File

@@ -14,6 +14,8 @@ import { getLifeCycleTarger } from '../..';
* *
* @example * @example
* const isMounted = useMounted(getCurrentInstance()); * const isMounted = useMounted(getCurrentInstance());
*
* @since 0.0.1
*/ */
export function useMounted(instance?: ComponentInternalInstance) { export function useMounted(instance?: ComponentInternalInstance) {
const isMounted = ref(false); const isMounted = ref(false);

View File

@@ -63,6 +63,8 @@ export type UseOffsetPaginationInfinityReturn = Omit<UseOffsetPaginationReturn,
* onPageSizeChange: ({ currentPageSize }) => console.log(currentPageSize), * onPageSizeChange: ({ currentPageSize }) => console.log(currentPageSize),
* onTotalPagesChange: ({ totalPages }) => console.log(totalPages), * onTotalPagesChange: ({ totalPages }) => console.log(totalPages),
* }); * });
*
* @since 0.0.1
*/ */
export function useOffsetPagination(options: Omit<UseOffsetPaginationOptions, 'total'>): UseOffsetPaginationInfinityReturn; export function useOffsetPagination(options: Omit<UseOffsetPaginationOptions, 'total'>): UseOffsetPaginationInfinityReturn;
export function useOffsetPagination(options: UseOffsetPaginationOptions): UseOffsetPaginationReturn; export function useOffsetPagination(options: UseOffsetPaginationOptions): UseOffsetPaginationReturn;

View File

@@ -15,6 +15,8 @@ import { getLifeCycleTarger } from '../..';
* *
* @example * @example
* const count = useRenderCount(getCurrentInstance()); * const count = useRenderCount(getCurrentInstance());
*
* @since 0.0.1
*/ */
export function useRenderCount(instance?: ComponentInternalInstance) { export function useRenderCount(instance?: ComponentInternalInstance) {
const { count, increment } = useCounter(0); const { count, increment } = useCounter(0);

View File

@@ -1,3 +1,4 @@
import { timestamp } from '@robonen/stdlib';
import { onBeforeMount, onBeforeUpdate, onMounted, onUpdated, readonly, ref, type ComponentInternalInstance } from 'vue'; import { onBeforeMount, onBeforeUpdate, onMounted, onUpdated, readonly, ref, type ComponentInternalInstance } from 'vue';
import { useRenderCount } from '../useRenderCount'; import { useRenderCount } from '../useRenderCount';
import { getLifeCycleTarger } from '../..'; import { getLifeCycleTarger } from '../..';
@@ -15,6 +16,8 @@ import { getLifeCycleTarger } from '../..';
* *
* @example * @example
* const { component, count, duration, lastRendered } = useRenderInfo(getCurrentInstance()); * const { component, count, duration, lastRendered } = useRenderInfo(getCurrentInstance());
*
* @since 0.0.1
*/ */
export function useRenderInfo(instance?: ComponentInternalInstance) { export function useRenderInfo(instance?: ComponentInternalInstance) {
const target = getLifeCycleTarger(instance); const target = getLifeCycleTarger(instance);
@@ -33,6 +36,6 @@ export function useRenderInfo(instance?: ComponentInternalInstance) {
component: target?.type.name ?? target?.uid, component: target?.type.name ?? target?.uid,
count: useRenderCount(instance), count: useRenderCount(instance),
duration: readonly(duration), duration: readonly(duration),
lastRendered: Date.now(), lastRendered: timestamp(),
}; };
} }

View File

@@ -14,6 +14,8 @@ import { useMounted } from '../useMounted';
* *
* @example * @example
* const isSupported = useSupported(() => 'ResizeObserver' in window); * const isSupported = useSupported(() => 'ResizeObserver' in window);
*
* @since 0.0.1
*/ */
export function useSupported(feature: () => unknown) { export function useSupported(feature: () => unknown) {
const isMounted = useMounted(); const isMounted = useMounted();

View File

@@ -21,6 +21,8 @@ import { isArray } from '@robonen/stdlib';
* const source = ref(0); * const source = ref(0);
* const target1 = ref(0); * const target1 = ref(0);
* useSyncRefs(source, target1, { immediate: true }); * useSyncRefs(source, target1, { immediate: true });
*
* @since 0.0.1
*/ */
export function useSyncRefs<T = unknown>( export function useSyncRefs<T = unknown>(
source: WatchSource<T>, source: WatchSource<T>,

View File

@@ -1,5 +1,21 @@
import { getCurrentInstance, type ComponentInternalInstance } from 'vue'; import { getCurrentInstance, type ComponentInternalInstance } from 'vue';
/**
* @name getLifeCycleTarger
* @category Utils
* @description Function to get the target instance of the lifecycle hook
*
* @param {ComponentInternalInstance} target The target instance of the lifecycle hook
* @returns {ComponentInternalInstance | null} Instance of the lifecycle hook or null
*
* @example
* const target = getLifeCycleTarger();
*
* @example
* const target = getLifeCycleTarger(instance);
*
* @since 0.0.1
*/
export function getLifeCycleTarger(target?: ComponentInternalInstance) { export function getLifeCycleTarger(target?: ComponentInternalInstance) {
return target || getCurrentInstance(); return target || getCurrentInstance();
} }

View File

@@ -1,3 +1,10 @@
/**
* @name VueToolsError
* @category Error
* @description VueToolsError is a custom error class that represents an error in Vue Tools
*
* @since 0.0.1
*/
export class VueToolsError extends Error { export class VueToolsError extends Error {
constructor(message: string) { constructor(message: string) {
super(message); super(message);