Skip to content

Commit

Permalink
Merge branch 'develop' into docs/programmatic
Browse files Browse the repository at this point in the history
  • Loading branch information
mlmoravek committed Jan 21, 2025
2 parents 5f62f06 + c9b7e25 commit 4bd8c92
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/oruga/src/components/loading/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@/utils/plugins";

/** export loading specific types */
// no types to export here
export type { LoadingProgrammaticOptions } from "./useLoadingProgrammatic";

/** export loading plugin */
export default {
Expand Down
10 changes: 6 additions & 4 deletions packages/oruga/src/components/loading/useLoadingProgrammatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ declare module "../../index" {
const instances = new InstanceRegistry<ComponentInternalInstance>();

/** useLoadingProgrammatic composable options */
type LoadingProgrammaticOptions = Readonly<Omit<LoadingProps, "label">> & {
export type LoadingProgrammaticOptions = Readonly<
Omit<LoadingProps, "label">
> & {
label?: string | Array<unknown>;
} & ProgrammaticComponentOptions;

const LoadingProgrammatic = {
/**
* Create a new programmatic loading component.
* Create a new programmatic loading component instance.
* @param options loading label string or loading component props object
* @param target specify a target the component get rendered into
* @returns ProgrammaticExpose
Expand Down Expand Up @@ -64,11 +66,11 @@ const LoadingProgrammatic = {
slot,
);
},
/** close the last registred instance in the loading programmatic instance registry */
/** Close the last registred instance in the loading programmatic instance registry. */
close(...args: unknown[]): void {
instances.last()?.exposed?.close(...args);
},
/** close all instances in the programmatic loading instance registry */
/** Close all instances in the programmatic loading instance registry. */
closeAll(...args: unknown[]): void {
instances.walk((entry) => entry.exposed?.close(...args));
},
Expand Down
2 changes: 1 addition & 1 deletion packages/oruga/src/components/modal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@/utils/plugins";

/** export modal specific types */
// no types to export here
export type { ModalProgrammaticOptions } from "./useModalProgrammatic";

/** export modal plugin */
export default {
Expand Down
8 changes: 4 additions & 4 deletions packages/oruga/src/components/modal/useModalProgrammatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ declare module "../../index" {
const instances = new InstanceRegistry<ComponentInternalInstance>();

/** useModalProgrammatic composable options */
type ModalProgrammaticOptions<C extends Component> = Readonly<
export type ModalProgrammaticOptions<C extends Component> = Readonly<
Omit<ModalProps<C>, "content">
> & {
content?: string | Array<unknown>;
} & ProgrammaticComponentOptions;

const ModalProgrammatic = {
/**
* Create a new programmatic modal component.
* Create a new programmatic modal component instance.
* @param options modal content string or modal component props object
* @param target specify a target the component get rendered into - default is `document.body`
* @returns ProgrammaticExpose
Expand Down Expand Up @@ -69,11 +69,11 @@ const ModalProgrammatic = {
slot,
);
},
/** close the last registred instance in the modal programmatic instance registry */
/** Close the last registred instance in the modal programmatic instance registry. */
close(...args: unknown[]): void {
instances.last()?.exposed?.close(...args);
},
/** close all instances in the programmatic modal instance registry */
/** Close all instances in the programmatic modal instance registry. */
closeAll(...args: unknown[]): void {
instances.walk((entry) => entry.exposed?.close(...args));
},
Expand Down
2 changes: 1 addition & 1 deletion packages/oruga/src/components/notification/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@/utils/plugins";

/** export notification specific types */
// no types to export here
export type { NotificationProgrammaticOptions } from "./useNotificationProgrammatic";

/** export notification plugin */
export default {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ declare module "../../index" {
const instances = new InstanceRegistry<ComponentInternalInstance>();

/** useNotificationProgrammatic composable options */
type NotificationProgrammaticOptions<C extends Component> = Readonly<
export type NotificationProgrammaticOptions<C extends Component> = Readonly<
Omit<
NotificationNoticeProps<C> & NotificationProps,
"message" | "container"
Expand All @@ -31,8 +31,10 @@ type NotificationProgrammaticOptions<C extends Component> = Readonly<
} & ProgrammaticComponentOptions;

const NotificationProgrammatic = {
/** Returns the number of registered active instances. */
count: instances.count,
/**
* Create a new programmatic notification component.
* Create a new programmatic notification component instance.
* @param options notification message string or notification component props object
* @param target specify a target the component get rendered into - default is `document.body`
* @returns ProgrammaticExpose
Expand Down Expand Up @@ -70,11 +72,11 @@ const NotificationProgrammatic = {
slot,
);
},
/** close the last registred instance in the notification programmatic instance registry */
/** Close the last registred instance in the notification programmatic instance registry. */
close(...args: unknown[]): void {
instances.last()?.exposed?.close(...args);
},
/** close all instances in the programmatic notification instance registry */
/** Close all instances in the programmatic notification instance registry. */
closeAll(...args: unknown[]): void {
instances.walk((entry) => entry.exposed?.close(...args));
},
Expand Down
10 changes: 10 additions & 0 deletions packages/oruga/src/components/programmatic/InstanceRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,33 @@ export default class InstanceRegistry<T = ComponentInternalInstance> {
this.entries = [];
}

/** Returns the number of registered active instances. */
count(): number {
return this.entries.length;
}

/** Returns the first registered active instance. */
fist(): T | undefined {
return this.entries.at(0);
}

/** Returns the last registered active instance. */
last(): T | undefined {
return this.entries.at(-1);
}

/** Adds a new instance to the instance stack. */
add(entry: T): void {
this.entries.push(entry);
}

/** Removes an instance from the instance stack. */
remove(entry: T): void {
const index = this.entries.indexOf(entry);
this.entries.splice(index, 1);
}

/** Call a function for every registered active instance. */
walk(callback: (value: T) => boolean | void): void {
// Walk a copy of the array so that the callback is allowed to remove the instance
this.entries = [...this.entries].filter((e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import {
type VNode,
type VNodeTypes,
} from "vue";
import type {
// ComponentExposed,
ComponentProps,
} from "vue-component-type-helpers";

import type { ComponentProps } from "vue-component-type-helpers";
import type InstanceRegistry from "@/components/programmatic/InstanceRegistry";
import { isClient } from "@/utils/ssr";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ export type ProgrammaticComponentOptions = EmitsToProps<
export type ProgrammaticExpose = ProgrammaticComponentExpose;

export const ComponentProgrammatic = {
/** Returns the number of registered active instances. */
count: instances.count,
/**
* Create a new programmatic component.
* Create a new programmatic component instance.
* @param component component to render
* @param options render options
* @param slot default slot content - see {@link https://vuejs.org/api/render-function.html#render-function-apis |Vue render function}
Expand Down
2 changes: 1 addition & 1 deletion packages/oruga/src/components/sidebar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@/utils/plugins";

/** export sidebar specific types */
// no types to export here
export type { SidebarProgrammaticOptions } from "./useSidebarProgrammatic";

/** export sidebar plugin */
export default {
Expand Down
10 changes: 6 additions & 4 deletions packages/oruga/src/components/sidebar/useSidebarProgrammatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ declare module "../../index" {
const instances = new InstanceRegistry<ComponentInternalInstance>();

/** useSidebarProgrammatic composable options */
type SidebarProgrammaticOptions<C extends Component> = Readonly<
export type SidebarProgrammaticOptions<C extends Component> = Readonly<
SidebarProps<C>
> &
ProgrammaticComponentOptions;

const SidebarProgrammatic = {
/** Returns the number of registered active instances. */
count: instances.count,
/**
* Create a new programmatic sidebar component.
* Create a new programmatic sidebar component instance.
* @param options sidebar component props object
* @param target specify a target the component get rendered into - default is `document.body`
* @returns ProgrammaticExpose
Expand All @@ -53,11 +55,11 @@ const SidebarProgrammatic = {
onClose: options.onClose, // on close event handler
});
},
/** close the last registred instance in the sidebar programmatic instance registry */
/** Close the last registred instance in the sidebar programmatic instance registry. */
close(...args: unknown[]): void {
instances.last()?.exposed?.close(...args);
},
/** close all instances in the programmatic sidebar instance registry */
/** Close all instances in the programmatic sidebar instance registry. */
closeAll(...args: unknown[]): void {
instances.walk((entry) => entry.exposed?.close(...args));
},
Expand Down

0 comments on commit 4bd8c92

Please sign in to comment.