nuance-ui 0.1.57 → 0.1.59

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 (31) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/module.mjs +1 -1
  3. package/dist/runtime/components/combobox/combobox-root.d.vue.ts +2 -2
  4. package/dist/runtime/components/combobox/combobox-root.vue.d.ts +2 -2
  5. package/dist/runtime/components/index.d.ts +0 -1
  6. package/dist/runtime/components/index.js +0 -1
  7. package/dist/runtime/components/select/select.d.vue.ts +2 -2
  8. package/dist/runtime/components/select/select.vue.d.ts +2 -2
  9. package/dist/runtime/composals/index.d.ts +0 -1
  10. package/dist/runtime/composals/index.js +0 -1
  11. package/dist/runtime/{components/modals → modals}/_confirm-modal/confirm-modal.d.vue.ts +3 -4
  12. package/dist/runtime/{components/modals → modals}/_confirm-modal/confirm-modal.vue +7 -22
  13. package/dist/runtime/{components/modals → modals}/_confirm-modal/confirm-modal.vue.d.ts +3 -4
  14. package/dist/runtime/{components/modals → modals}/_confirm-modal/index.d.ts +1 -1
  15. package/dist/runtime/{components/modals → modals}/_confirm-modal/index.js +1 -1
  16. package/dist/runtime/modals/index.d.ts +4 -0
  17. package/dist/runtime/modals/index.js +4 -0
  18. package/dist/runtime/modals/modal-manager.d.ts +73 -0
  19. package/dist/runtime/modals/modal-manager.js +70 -0
  20. package/dist/runtime/{components/modals → modals}/modals-provider.vue +1 -1
  21. package/dist/runtime/{composals → modals}/use-modal.js +1 -1
  22. package/package.json +1 -1
  23. package/dist/runtime/components/modals/index.d.ts +0 -1
  24. package/dist/runtime/components/modals/index.js +0 -1
  25. package/dist/runtime/plugins/modals/index.d.ts +0 -2
  26. package/dist/runtime/plugins/modals/index.js +0 -3
  27. package/dist/runtime/plugins/modals/modal-manager.d.ts +0 -78
  28. package/dist/runtime/plugins/modals/modal-manager.js +0 -107
  29. /package/dist/runtime/{components/modals → modals}/modals-provider.d.vue.ts +0 -0
  30. /package/dist/runtime/{components/modals → modals}/modals-provider.vue.d.ts +0 -0
  31. /package/dist/runtime/{composals → modals}/use-modal.d.ts +0 -0
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^4.0.0"
6
6
  },
7
- "version": "0.1.57",
7
+ "version": "0.1.59",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -37,7 +37,7 @@ const module$1 = defineNuxtModule({
37
37
  nuxt.options.alias["@nui/utils"] = resolve("./runtime/utils");
38
38
  nuxt.options.alias["@nui/helpers"] = resolve("./runtime/helpers");
39
39
  nuxt.options.alias["@nui/types"] = resolve("./runtime/types");
40
- nuxt.options.alias["@nui/modals"] = resolve("./runtime/plugins/modals");
40
+ nuxt.options.alias["@nui/modals"] = resolve("./runtime/modals");
41
41
  nuxt.options.appConfig.nui = defu(nuxt.options.appConfig.nui || {}, defaultConfig);
42
42
  nuxt.options.postcss = nuxt.options.postcss || {};
43
43
  nuxt.options.postcss.plugins = nuxt.options.postcss.plugins || {};
@@ -25,15 +25,15 @@ type __VLS_Slots = {} & {
25
25
  default?: (props: typeof __VLS_8) => any;
26
26
  };
27
27
  declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
28
- clear: () => any;
29
28
  select: (args_0: number) => any;
29
+ clear: () => any;
30
30
  close: (args_0: import("./types/index.js").ComboboxDropdownEventSource) => any;
31
31
  submit: (args_0: string, args_1: import("./types/index.js").ComboboxItem) => any;
32
32
  open: (args_0: import("./types/index.js").ComboboxDropdownEventSource) => any;
33
33
  "update:open": (value: boolean) => any;
34
34
  }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
35
- onClear?: (() => any) | undefined;
36
35
  onSelect?: ((args_0: number) => any) | undefined;
36
+ onClear?: (() => any) | undefined;
37
37
  onClose?: ((args_0: import("./types/index.js").ComboboxDropdownEventSource) => any) | undefined;
38
38
  onSubmit?: ((args_0: string, args_1: import("./types/index.js").ComboboxItem) => any) | undefined;
39
39
  onOpen?: ((args_0: import("./types/index.js").ComboboxDropdownEventSource) => any) | undefined;
@@ -25,15 +25,15 @@ type __VLS_Slots = {} & {
25
25
  default?: (props: typeof __VLS_8) => any;
26
26
  };
27
27
  declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
28
- clear: () => any;
29
28
  select: (args_0: number) => any;
29
+ clear: () => any;
30
30
  close: (args_0: import("./types/index.js").ComboboxDropdownEventSource) => any;
31
31
  submit: (args_0: string, args_1: import("./types/index.js").ComboboxItem) => any;
32
32
  open: (args_0: import("./types/index.js").ComboboxDropdownEventSource) => any;
33
33
  "update:open": (value: boolean) => any;
34
34
  }, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
35
- onClear?: (() => any) | undefined;
36
35
  onSelect?: ((args_0: number) => any) | undefined;
36
+ onClear?: (() => any) | undefined;
37
37
  onClose?: ((args_0: import("./types/index.js").ComboboxDropdownEventSource) => any) | undefined;
38
38
  onSubmit?: ((args_0: string, args_1: import("./types/index.js").ComboboxItem) => any) | undefined;
39
39
  onOpen?: ((args_0: import("./types/index.js").ComboboxDropdownEventSource) => any) | undefined;
@@ -20,7 +20,6 @@ export * from './input/index.js';
20
20
  export * from './link/index.js';
21
21
  export * from './loader/index.js';
22
22
  export * from './modal/index.js';
23
- export * from './modals/index.js';
24
23
  export * from './nav-link/index.js';
25
24
  export * from './paper.vue.js';
26
25
  export * from './popover/index.js';
@@ -18,7 +18,6 @@ export * from "./input/index.js";
18
18
  export * from "./link/index.js";
19
19
  export * from "./loader/index.js";
20
20
  export * from "./modal/index.js";
21
- export * from "./modals/index.js";
22
21
  export * from "./nav-link/index.js";
23
22
  export * from "./paper.vue";
24
23
  export * from "./popover/index.js";
@@ -24,8 +24,8 @@ declare const __VLS_export: <Value extends string = string, Ext extends Combobox
24
24
  modelValue?: ComboboxItem<Value, Ext> | null;
25
25
  search?: string;
26
26
  }) & {
27
- onClear?: (() => any) | undefined;
28
27
  onSelect?: ((args_0: number) => any) | undefined;
28
+ onClear?: (() => any) | undefined;
29
29
  onClose?: ((args_0: import("..").ComboboxDropdownEventSource) => any) | undefined;
30
30
  onSubmit?: ((args_0: string, args_1: ComboboxItem) => any) | undefined;
31
31
  "onUpdate:modelValue"?: ((value: ComboboxItem<Value, Ext> | null) => any) | undefined;
@@ -48,7 +48,7 @@ declare const __VLS_export: <Value extends string = string, Ext extends Combobox
48
48
  } & {
49
49
  rightSection?: (props: {}) => any;
50
50
  };
51
- emit: (((evt: "clear") => void) & ((evt: "select", args_0: number) => void) & ((evt: "close", args_0: import("..").ComboboxDropdownEventSource) => void) & ((evt: "submit", args_0: string, args_1: ComboboxItem) => void) & ((evt: "open", args_0: import("..").ComboboxDropdownEventSource) => void)) & (((event: "update:modelValue", value: ComboboxItem<Value, Ext> | null) => void) & ((event: "update:search", value: string) => void) & ((event: "update:open", value: boolean) => void));
51
+ emit: (((evt: "select", args_0: number) => void) & ((evt: "clear") => void) & ((evt: "close", args_0: import("..").ComboboxDropdownEventSource) => void) & ((evt: "submit", args_0: string, args_1: ComboboxItem) => void) & ((evt: "open", args_0: import("..").ComboboxDropdownEventSource) => void)) & (((event: "update:modelValue", value: ComboboxItem<Value, Ext> | null) => void) & ((event: "update:search", value: string) => void) & ((event: "update:open", value: boolean) => void));
52
52
  }>) => import("vue").VNode & {
53
53
  __ctx?: Awaited<typeof __VLS_setup>;
54
54
  };
@@ -24,8 +24,8 @@ declare const __VLS_export: <Value extends string = string, Ext extends Combobox
24
24
  modelValue?: ComboboxItem<Value, Ext> | null;
25
25
  search?: string;
26
26
  }) & {
27
- onClear?: (() => any) | undefined;
28
27
  onSelect?: ((args_0: number) => any) | undefined;
28
+ onClear?: (() => any) | undefined;
29
29
  onClose?: ((args_0: import("..").ComboboxDropdownEventSource) => any) | undefined;
30
30
  onSubmit?: ((args_0: string, args_1: ComboboxItem) => any) | undefined;
31
31
  "onUpdate:modelValue"?: ((value: ComboboxItem<Value, Ext> | null) => any) | undefined;
@@ -48,7 +48,7 @@ declare const __VLS_export: <Value extends string = string, Ext extends Combobox
48
48
  } & {
49
49
  rightSection?: (props: {}) => any;
50
50
  };
51
- emit: (((evt: "clear") => void) & ((evt: "select", args_0: number) => void) & ((evt: "close", args_0: import("..").ComboboxDropdownEventSource) => void) & ((evt: "submit", args_0: string, args_1: ComboboxItem) => void) & ((evt: "open", args_0: import("..").ComboboxDropdownEventSource) => void)) & (((event: "update:modelValue", value: ComboboxItem<Value, Ext> | null) => void) & ((event: "update:search", value: string) => void) & ((event: "update:open", value: boolean) => void));
51
+ emit: (((evt: "select", args_0: number) => void) & ((evt: "clear") => void) & ((evt: "close", args_0: import("..").ComboboxDropdownEventSource) => void) & ((evt: "submit", args_0: string, args_1: ComboboxItem) => void) & ((evt: "open", args_0: import("..").ComboboxDropdownEventSource) => void)) & (((event: "update:modelValue", value: ComboboxItem<Value, Ext> | null) => void) & ((event: "update:search", value: string) => void) & ((event: "update:open", value: boolean) => void));
52
52
  }>) => import("vue").VNode & {
53
53
  __ctx?: Awaited<typeof __VLS_setup>;
54
54
  };
@@ -1,5 +1,4 @@
1
1
  export * from './use-active-link.js';
2
2
  export * from './use-date-config.js';
3
- export * from './use-modal.js';
4
3
  export * from './use-style-resolver.js';
5
4
  export * from './use-theme.js';
@@ -1,5 +1,4 @@
1
1
  export * from "./use-active-link.js";
2
2
  export * from "./use-date-config.js";
3
- export * from "./use-modal.js";
4
3
  export * from "./use-style-resolver.js";
5
4
  export * from "./use-theme.js";
@@ -1,8 +1,7 @@
1
- import type { MaybePromise } from '@nui/types';
2
- import type { ButtonProps } from '../../button/button.vue.js';
3
- import type { ModalRootProps } from '../../modal/modal-root.vue.js';
1
+ import type { ButtonProps, ModalRootProps } from '../../components/index.js';
2
+ import type { MaybePromise } from '../../types/index.js';
4
3
  type ConfirmLabels = Record<'confirm' | 'cancel', string>;
5
- export interface ConfirmModalProps extends ModalRootProps {
4
+ export interface ConfirmModalProps extends /* @vue-ignore */ ModalRootProps {
6
5
  /** Modal title */
7
6
  title: string;
8
7
  /** Description text displayed below the title */
@@ -1,11 +1,11 @@
1
1
  <script setup>
2
- import { useModal } from "@nui/composals";
3
2
  import { ref } from "vue";
4
- import Button from "../../button/button.vue";
5
- import ModalCloseButton from "../../modal/modal-close-button.vue";
6
- import ModalHeader from "../../modal/modal-header.vue";
7
- import ModalRoot from "../../modal/modal-root.vue";
8
- import Title from "../../title.vue";
3
+ import Button from "../../components/button/button.vue";
4
+ import ModalCloseButton from "../../components/modal/modal-close-button.vue";
5
+ import ModalHeader from "../../components/modal/modal-header.vue";
6
+ import ModalRoot from "../../components/modal/modal-root.vue";
7
+ import Title from "../../components/title.vue";
8
+ import { useModal } from "../use-modal";
9
9
  const {
10
10
  title,
11
11
  description: body,
@@ -25,22 +25,7 @@ const {
25
25
  onCancel: { type: Function, required: false },
26
26
  onConfirm: { type: Function, required: false },
27
27
  cancelProps: { type: Object, required: false },
28
- confirmProps: { type: Object, required: false },
29
- centered: { type: Boolean, required: false },
30
- fullScreen: { type: Boolean, required: false },
31
- closeOnClickOutside: { type: Boolean, required: false },
32
- withinPortal: { type: Boolean, required: false },
33
- withoutOverlay: { type: Boolean, required: false },
34
- yOffset: { type: void 0, required: false },
35
- xOffset: { type: void 0, required: false },
36
- radius: { type: [String, Number], required: false },
37
- size: { type: String, required: false },
38
- shadow: { type: String, required: false },
39
- padding: { type: [String, Number], required: false },
40
- transition: { type: String, required: false },
41
- portalTarget: { type: [String, Object, null], required: false },
42
- is: { type: null, required: false },
43
- mod: { type: [Object, Array, null], required: false }
28
+ confirmProps: { type: Object, required: false }
44
29
  });
45
30
  const { opened, resolve: hide } = useModal("confirm");
46
31
  const loading = ref(false);
@@ -1,8 +1,7 @@
1
- import type { MaybePromise } from '@nui/types';
2
- import type { ButtonProps } from '../../button/button.vue.js';
3
- import type { ModalRootProps } from '../../modal/modal-root.vue.js';
1
+ import type { ButtonProps, ModalRootProps } from '../../components/index.js';
2
+ import type { MaybePromise } from '../../types/index.js';
4
3
  type ConfirmLabels = Record<'confirm' | 'cancel', string>;
5
- export interface ConfirmModalProps extends ModalRootProps {
4
+ export interface ConfirmModalProps extends /* @vue-ignore */ ModalRootProps {
6
5
  /** Modal title */
7
6
  title: string;
8
7
  /** Description text displayed below the title */
@@ -4,5 +4,5 @@ import type { ConfirmModalProps } from './confirm-modal.vue.js';
4
4
  *
5
5
  * Resolves with `true` if the user confirmed, rejects if cancelled.
6
6
  */
7
- export declare const openConfirmModal: (props?: ConfirmModalProps | undefined) => Promise<boolean>;
7
+ export declare const openConfirmModal: (props?: any) => Promise<boolean>;
8
8
  export type { ConfirmModalProps };
@@ -1,4 +1,4 @@
1
- import { $modals } from "../../../plugins/modals/index.js";
1
+ import { $modals } from "../modal-manager.js";
2
2
  import ConfirmModal from "./confirm-modal.vue";
3
3
  export const openConfirmModal = $modals.create(
4
4
  "confirm",
@@ -0,0 +1,4 @@
1
+ export * from './_confirm-modal/index.js';
2
+ export { $modals } from './modal-manager.js';
3
+ export { default as NModalsProvider } from './modals-provider.vue.js';
4
+ export * from './use-modal.js';
@@ -0,0 +1,4 @@
1
+ export * from "./_confirm-modal/index.js";
2
+ export { $modals } from "./modal-manager.js";
3
+ export { default as NModalsProvider } from "./modals-provider.vue";
4
+ export * from "./use-modal.js";
@@ -0,0 +1,73 @@
1
+ import type { Component } from 'vue';
2
+ /**
3
+ * Reactive state of a single modal within the modal manager.
4
+ */
5
+ export interface ModalState<Props extends object = object, Resolve = unknown, Reject = unknown> {
6
+ /** Unique modal identifier */
7
+ id: string;
8
+ /** Vue component rendered as the modal */
9
+ component: Component;
10
+ /** Props passed when calling `show` or the opener function */
11
+ props: Props;
12
+ /** Current visibility state */
13
+ opened: boolean;
14
+ /** Resolves the promise created when the modal was opened */
15
+ resolve: (value?: Resolve) => void;
16
+ /** Rejects the promise created when the modal was opened */
17
+ reject: (reason?: Reject) => void;
18
+ }
19
+ declare function show<T = unknown>(id: string, props?: object): Promise<T>;
20
+ /**
21
+ * Registers a modal component and returns a typed function to open it.
22
+ */
23
+ declare function create<TProps extends object = object, TResult = void>(
24
+ /** unique modal identifier */
25
+ id: string,
26
+ /** Vue component for the modal */
27
+ component: Component): (props?: TProps) => Promise<TResult>;
28
+ /**
29
+ * Registers a lazy modal — the component is loaded on first open.
30
+ */
31
+ declare function createLazy<TProps extends object = object, TResult = void>(
32
+ /** unique modal identifier */
33
+ id: string,
34
+ /** dynamic import function (`() => import('./my-modal.vue')`) */
35
+ loader: () => Promise<{
36
+ default: Component;
37
+ }>): (props?: Omit<TProps, 'modalId'>) => Promise<TResult>;
38
+ /**
39
+ * Closes the modal and resolves its promise with the given result.
40
+ */
41
+ declare function resolve(id: string, result?: any): void;
42
+ /**
43
+ * Closes the modal and rejects its promise with the given reason.
44
+ */
45
+ declare function reject(id: string, reason?: any): void;
46
+ /**
47
+ * Returns the reactive state of a specific modal.
48
+ * Used inside a modal component (via {@link useModal}).
49
+ */
50
+ declare function state<Props extends object = object, Resolve = unknown, Reject = unknown>(id: string): ModalState<Props, Resolve, Reject>;
51
+ /**
52
+ * Modal manager.
53
+ *
54
+ * Maintains a component registry and a reactive map of active modals.
55
+ * Opening a modal returns a `Promise` that resolves via `resolve`
56
+ * or rejects via `reject` / user dismissal.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const open = $modals.create<MyProps, string>('my-modal', MyModal)
61
+ * const result = await open({ foo: 'bar' }) // result: string
62
+ * ```
63
+ */
64
+ export declare const $modals: import("vue").Raw<{
65
+ modals: import("vue").Reactive<Map<string, ModalState<object, unknown, unknown>>>;
66
+ create: typeof create;
67
+ createLazy: typeof createLazy;
68
+ show: typeof show;
69
+ resolve: typeof resolve;
70
+ reject: typeof reject;
71
+ state: typeof state;
72
+ }>;
73
+ export {};
@@ -0,0 +1,70 @@
1
+ import { markRaw, reactive } from "vue";
2
+ const modals = reactive(/* @__PURE__ */ new Map());
3
+ const registered = /* @__PURE__ */ new Map();
4
+ const lazy = /* @__PURE__ */ new Map();
5
+ async function show(id, props = {}) {
6
+ if (!registered.has(id) && lazy.has(id)) {
7
+ const loader = lazy.get(id);
8
+ try {
9
+ const loaded = await loader();
10
+ registered.set(id, loaded.default);
11
+ } catch (err) {
12
+ return Promise.reject(err);
13
+ }
14
+ }
15
+ const component = registered.get(id);
16
+ if (!component)
17
+ return Promise.reject(new Error(`Modal "${id}" is not registered`));
18
+ const existing = modals.get(id);
19
+ return new Promise((resolve2, reject2) => {
20
+ if (existing) {
21
+ existing.props = props;
22
+ existing.opened = true;
23
+ existing.resolve = resolve2;
24
+ existing.reject = reject2;
25
+ } else {
26
+ modals.set(id, {
27
+ id,
28
+ component: markRaw(component),
29
+ props,
30
+ opened: true,
31
+ resolve: resolve2,
32
+ reject: reject2
33
+ });
34
+ }
35
+ });
36
+ }
37
+ function create(id, component) {
38
+ registered.set(id, component);
39
+ return (props) => show(id, props ?? {});
40
+ }
41
+ function createLazy(id, loader) {
42
+ lazy.set(id, loader);
43
+ return (props) => show(id, props ?? {});
44
+ }
45
+ function resolve(id, result) {
46
+ const modal = modals.get(id);
47
+ if (!modal)
48
+ return;
49
+ modal.opened = false;
50
+ modal.resolve?.(result);
51
+ }
52
+ function reject(id, reason) {
53
+ const modal = modals.get(id);
54
+ if (!modal)
55
+ return;
56
+ modal.opened = false;
57
+ modal.reject?.(reason);
58
+ }
59
+ function state(id) {
60
+ return modals.get(id);
61
+ }
62
+ export const $modals = markRaw({
63
+ modals,
64
+ create,
65
+ createLazy,
66
+ show,
67
+ resolve,
68
+ reject,
69
+ state
70
+ });
@@ -1,5 +1,5 @@
1
1
  <script setup>
2
- import { $modals } from "../../plugins/modals";
2
+ import { $modals } from "./modal-manager";
3
3
  </script>
4
4
 
5
5
  <template>
@@ -1,5 +1,5 @@
1
1
  import { computed } from "vue";
2
- import { $modals } from "../plugins/modals/index.js";
2
+ import { $modals } from "./modal-manager.js";
3
3
  export function useModal(id) {
4
4
  const state = computed(() => $modals.state(id));
5
5
  const opened = computed({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuance-ui",
3
- "version": "0.1.57",
3
+ "version": "0.1.59",
4
4
  "description": "A UI Library for Modern Web Apps, powered by Vue.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1 +0,0 @@
1
- export * from './_confirm-modal/index.js';
@@ -1 +0,0 @@
1
- export * from "./_confirm-modal/index.js";
@@ -1,2 +0,0 @@
1
- import { ModalManager } from './modal-manager.js';
2
- export declare const $modals: import("vue").Raw<ModalManager>;
@@ -1,3 +0,0 @@
1
- import { markRaw } from "vue";
2
- import { ModalManager } from "./modal-manager.js";
3
- export const $modals = markRaw(new ModalManager());
@@ -1,78 +0,0 @@
1
- import type { Component } from 'vue';
2
- /**
3
- * Reactive state of a single modal within {@link ModalManager}.
4
- */
5
- export interface ModalState<Props extends object = object, Resolve = unknown, Reject = unknown> {
6
- /** Unique modal identifier */
7
- id: string;
8
- /** Vue component rendered as the modal */
9
- component: Component;
10
- /** Props passed when calling `show` or the opener function */
11
- props: Props;
12
- /** Current visibility state */
13
- opened: boolean;
14
- /** Resolves the promise created when the modal was opened */
15
- resolve: (value?: Resolve) => void;
16
- /** Rejects the promise created when the modal was opened */
17
- reject: (reason?: Reject) => void;
18
- }
19
- /**
20
- * Modal manager.
21
- *
22
- * Maintains a component registry and a reactive map of active modals.
23
- * Opening a modal returns a `Promise` that resolves via `hide`
24
- * or rejects via `reject` / user dismissal.
25
- *
26
- * @example
27
- * ```ts
28
- * const open = $modals.create<MyProps, string>('my-modal', MyModal)
29
- * const result = await open({ foo: 'bar' }) // result: string
30
- * ```
31
- */
32
- export declare class ModalManager {
33
- #private;
34
- /** Reactive map of all active modals. Used by `ModalProvider` for rendering */
35
- get modals(): import("vue").Reactive<Map<string, ModalState<object, unknown, unknown>>>;
36
- /**
37
- * Registers a modal component and returns a typed function to open it.
38
- */
39
- create<TProps extends object = object, TResult = void>(
40
- /** unique modal identifier */
41
- id: string,
42
- /** Vue component for the modal */
43
- component: Component): (props?: TProps) => Promise<TResult>;
44
- /**
45
- * Registers a lazy modal — the component is loaded on first open.
46
- */
47
- createLazy<TProps extends object = object, TResult = void>(
48
- /** unique modal identifier */
49
- id: string,
50
- /** dynamic import function (`() => import('./my-modal.vue')`) */
51
- loader: () => Promise<{
52
- default: Component;
53
- }>): (props?: Omit<TProps, 'modalId'>) => Promise<TResult>;
54
- /**
55
- * Opens a previously registered modal by its identifier.
56
- */
57
- show<T = unknown>(id: string, props?: object): Promise<T>;
58
- /**
59
- * Closes the modal and resolves its promise with the given result.
60
- *
61
- * @param id — modal identifier
62
- * @param result — value the promise resolves with
63
- */
64
- resolve(id: string, result?: any): void;
65
- /**
66
- * Closes the modal and rejects its promise with the given reason.
67
- *
68
- * @param id — modal identifier
69
- * @param reason — rejection reason
70
- */
71
- reject(id: string, reason?: any): void;
72
- /**
73
- * Returns the reactive state of a specific modal as `ComputedRef<ModalState>`.
74
- *
75
- * Used inside a modal component (via {@link useModal}).
76
- */
77
- state<Props extends object = object, Resolve = unknown, Reject = unknown>(id: string): ModalState<Props, Resolve, Reject>;
78
- }
@@ -1,107 +0,0 @@
1
- import { markRaw, reactive } from "vue";
2
- export class ModalManager {
3
- /** Reactive map of active modals */
4
- #modals = reactive(/* @__PURE__ */ new Map());
5
- /** Eagerly registered components (id → Component) */
6
- #registered = /* @__PURE__ */ new Map();
7
- /** Lazily registered loaders (id → loader) */
8
- #lazy = /* @__PURE__ */ new Map();
9
- /** Reactive map of all active modals. Used by `ModalProvider` for rendering */
10
- get modals() {
11
- return this.#modals;
12
- }
13
- // ── Facade ──
14
- /**
15
- * Registers a modal component and returns a typed function to open it.
16
- */
17
- create(id, component) {
18
- this.#registered.set(id, component);
19
- return (props) => this.#show(id, props ?? {});
20
- }
21
- /**
22
- * Registers a lazy modal — the component is loaded on first open.
23
- */
24
- createLazy(id, loader) {
25
- this.#lazy.set(id, loader);
26
- return (props) => this.#show(id, props ?? {});
27
- }
28
- /**
29
- * Opens a previously registered modal by its identifier.
30
- */
31
- async show(id, props = {}) {
32
- return this.#show(id, props);
33
- }
34
- /**
35
- * Closes the modal and resolves its promise with the given result.
36
- *
37
- * @param id — modal identifier
38
- * @param result — value the promise resolves with
39
- */
40
- resolve(id, result) {
41
- this.#resolve(id, result);
42
- }
43
- /**
44
- * Closes the modal and rejects its promise with the given reason.
45
- *
46
- * @param id — modal identifier
47
- * @param reason — rejection reason
48
- */
49
- reject(id, reason) {
50
- this.#reject(id, reason);
51
- }
52
- /**
53
- * Returns the reactive state of a specific modal as `ComputedRef<ModalState>`.
54
- *
55
- * Used inside a modal component (via {@link useModal}).
56
- */
57
- state(id) {
58
- return this.#modals.get(id);
59
- }
60
- // ── Private implementation ──
61
- async #show(id, props = {}) {
62
- if (!this.#registered.has(id) && this.#lazy.has(id)) {
63
- const loader = this.#lazy.get(id);
64
- try {
65
- const loaded = await loader();
66
- this.#registered.set(id, loaded.default);
67
- } catch (err) {
68
- return Promise.reject(err);
69
- }
70
- }
71
- const component = this.#registered.get(id);
72
- if (!component)
73
- return Promise.reject(new Error(`Modal "${id}" is not registered`));
74
- const existing = this.#modals.get(id);
75
- return new Promise((resolve, reject) => {
76
- if (existing) {
77
- existing.props = props;
78
- existing.opened = true;
79
- existing.resolve = resolve;
80
- existing.reject = reject;
81
- } else {
82
- this.#modals.set(id, {
83
- id,
84
- component: markRaw(component),
85
- props,
86
- opened: true,
87
- resolve,
88
- reject
89
- });
90
- }
91
- });
92
- }
93
- #resolve(id, result) {
94
- const modal = this.#modals.get(id);
95
- if (!modal)
96
- return;
97
- modal.opened = false;
98
- modal.resolve?.(result);
99
- }
100
- #reject(id, reason) {
101
- const modal = this.#modals.get(id);
102
- if (!modal)
103
- return;
104
- modal.opened = false;
105
- modal.reject?.(reason);
106
- }
107
- }