nuance-ui 0.1.56 → 0.1.58
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/dist/module.json +1 -1
- package/dist/module.mjs +2 -6
- package/dist/runtime/components/index.d.ts +0 -1
- package/dist/runtime/components/index.js +0 -1
- package/dist/runtime/composals/index.d.ts +0 -1
- package/dist/runtime/composals/index.js +0 -1
- package/dist/runtime/{components/modals → modals}/_confirm-modal/confirm-modal.d.vue.ts +3 -4
- package/dist/runtime/{components/modals → modals}/_confirm-modal/confirm-modal.vue +7 -22
- package/dist/runtime/{components/modals → modals}/_confirm-modal/confirm-modal.vue.d.ts +3 -4
- package/dist/runtime/{components/modals → modals}/_confirm-modal/index.d.ts +1 -1
- package/dist/runtime/{components/modals → modals}/_confirm-modal/index.js +1 -1
- package/dist/runtime/modals/index.d.ts +4 -0
- package/dist/runtime/modals/index.js +4 -0
- package/dist/runtime/{plugins/modals → modals}/modal-manager.d.ts +7 -3
- package/dist/runtime/{plugins/modals → modals}/modal-manager.js +22 -17
- package/dist/runtime/modals/modals-provider.vue +16 -0
- package/dist/runtime/{composals → modals}/use-modal.d.ts +3 -3
- package/dist/runtime/{composals → modals}/use-modal.js +5 -6
- package/package.json +1 -1
- package/dist/runtime/components/modals/index.d.ts +0 -1
- package/dist/runtime/components/modals/index.js +0 -1
- package/dist/runtime/components/modals/modals-provider.vue +0 -19
- package/dist/runtime/plugins/modals/index.d.ts +0 -1
- package/dist/runtime/plugins/modals/index.js +0 -1
- package/dist/runtime/plugins/modals/plugin.client.d.ts +0 -8
- package/dist/runtime/plugins/modals/plugin.client.js +0 -10
- /package/dist/runtime/{components/modals → modals}/modals-provider.d.vue.ts +0 -0
- /package/dist/runtime/{components/modals → modals}/modals-provider.vue.d.ts +0 -0
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addComponentsDir, addImportsDir
|
|
1
|
+
import { defineNuxtModule, createResolver, addComponentsDir, addImportsDir } from '@nuxt/kit';
|
|
2
2
|
import { defu } from 'defu';
|
|
3
3
|
|
|
4
4
|
const defaultConfig = {
|
|
@@ -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/
|
|
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 || {};
|
|
@@ -70,10 +70,6 @@ const module$1 = defineNuxtModule({
|
|
|
70
70
|
addImportsDir(resolve("./runtime/composals"));
|
|
71
71
|
addImportsDir(resolve("./runtime/helpers"));
|
|
72
72
|
}
|
|
73
|
-
addPlugin({
|
|
74
|
-
src: resolve("./runtime/plugins/modals/plugin.client"),
|
|
75
|
-
mode: "client"
|
|
76
|
-
});
|
|
77
73
|
nuxt.options.css.push(resolve("./runtime/styles/global.css"));
|
|
78
74
|
}
|
|
79
75
|
});
|
|
@@ -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";
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
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 {
|
|
2
|
-
import type {
|
|
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?:
|
|
7
|
+
export declare const openConfirmModal: (props?: any) => Promise<boolean>;
|
|
8
8
|
export type { ConfirmModalProps };
|
|
@@ -29,10 +29,12 @@ export interface ModalState<Props extends object = object, Resolve = unknown, Re
|
|
|
29
29
|
* const result = await open({ foo: 'bar' }) // result: string
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
|
-
|
|
32
|
+
declare class ModalManager {
|
|
33
33
|
#private;
|
|
34
|
-
/** Reactive map of
|
|
35
|
-
|
|
34
|
+
/** Reactive map of active modals */
|
|
35
|
+
readonly modals: import("vue").Reactive<Map<string, ModalState<object, unknown, unknown>>>;
|
|
36
|
+
private constructor();
|
|
37
|
+
static get instance(): ModalManager;
|
|
36
38
|
/**
|
|
37
39
|
* Registers a modal component and returns a typed function to open it.
|
|
38
40
|
*/
|
|
@@ -76,3 +78,5 @@ export declare class ModalManager {
|
|
|
76
78
|
*/
|
|
77
79
|
state<Props extends object = object, Resolve = unknown, Reject = unknown>(id: string): ModalState<Props, Resolve, Reject>;
|
|
78
80
|
}
|
|
81
|
+
export declare const $modals: import("vue").Raw<ModalManager>;
|
|
82
|
+
export {};
|
|
@@ -1,35 +1,39 @@
|
|
|
1
1
|
import { markRaw, reactive } from "vue";
|
|
2
|
-
|
|
2
|
+
class ModalManager {
|
|
3
|
+
static #instance = null;
|
|
3
4
|
/** Reactive map of active modals */
|
|
4
|
-
|
|
5
|
+
modals = reactive(/* @__PURE__ */ new Map());
|
|
5
6
|
/** Eagerly registered components (id → Component) */
|
|
6
7
|
#registered = /* @__PURE__ */ new Map();
|
|
7
8
|
/** Lazily registered loaders (id → loader) */
|
|
8
9
|
#lazy = /* @__PURE__ */ new Map();
|
|
9
|
-
|
|
10
|
-
get modals() {
|
|
11
|
-
return this.#modals;
|
|
10
|
+
constructor() {
|
|
12
11
|
}
|
|
13
12
|
// ── Facade ──
|
|
13
|
+
static get instance() {
|
|
14
|
+
if (!this.#instance)
|
|
15
|
+
this.#instance = new ModalManager();
|
|
16
|
+
return this.#instance;
|
|
17
|
+
}
|
|
14
18
|
/**
|
|
15
19
|
* Registers a modal component and returns a typed function to open it.
|
|
16
20
|
*/
|
|
17
21
|
create(id, component) {
|
|
18
|
-
|
|
19
|
-
return (props) =>
|
|
22
|
+
ModalManager.instance.#registered.set(id, component);
|
|
23
|
+
return (props) => ModalManager.instance.#show(id, props ?? {});
|
|
20
24
|
}
|
|
21
25
|
/**
|
|
22
26
|
* Registers a lazy modal — the component is loaded on first open.
|
|
23
27
|
*/
|
|
24
28
|
createLazy(id, loader) {
|
|
25
|
-
|
|
26
|
-
return (props) =>
|
|
29
|
+
ModalManager.instance.#lazy.set(id, loader);
|
|
30
|
+
return (props) => ModalManager.instance.#show(id, props ?? {});
|
|
27
31
|
}
|
|
28
32
|
/**
|
|
29
33
|
* Opens a previously registered modal by its identifier.
|
|
30
34
|
*/
|
|
31
35
|
async show(id, props = {}) {
|
|
32
|
-
return
|
|
36
|
+
return ModalManager.instance.#show(id, props);
|
|
33
37
|
}
|
|
34
38
|
/**
|
|
35
39
|
* Closes the modal and resolves its promise with the given result.
|
|
@@ -38,7 +42,7 @@ export class ModalManager {
|
|
|
38
42
|
* @param result — value the promise resolves with
|
|
39
43
|
*/
|
|
40
44
|
resolve(id, result) {
|
|
41
|
-
|
|
45
|
+
ModalManager.instance.#resolve(id, result);
|
|
42
46
|
}
|
|
43
47
|
/**
|
|
44
48
|
* Closes the modal and rejects its promise with the given reason.
|
|
@@ -47,7 +51,7 @@ export class ModalManager {
|
|
|
47
51
|
* @param reason — rejection reason
|
|
48
52
|
*/
|
|
49
53
|
reject(id, reason) {
|
|
50
|
-
|
|
54
|
+
ModalManager.instance.#reject(id, reason);
|
|
51
55
|
}
|
|
52
56
|
/**
|
|
53
57
|
* Returns the reactive state of a specific modal as `ComputedRef<ModalState>`.
|
|
@@ -55,7 +59,7 @@ export class ModalManager {
|
|
|
55
59
|
* Used inside a modal component (via {@link useModal}).
|
|
56
60
|
*/
|
|
57
61
|
state(id) {
|
|
58
|
-
return
|
|
62
|
+
return ModalManager.instance.modals.get(id);
|
|
59
63
|
}
|
|
60
64
|
// ── Private implementation ──
|
|
61
65
|
async #show(id, props = {}) {
|
|
@@ -71,7 +75,7 @@ export class ModalManager {
|
|
|
71
75
|
const component = this.#registered.get(id);
|
|
72
76
|
if (!component)
|
|
73
77
|
return Promise.reject(new Error(`Modal "${id}" is not registered`));
|
|
74
|
-
const existing = this
|
|
78
|
+
const existing = this.modals.get(id);
|
|
75
79
|
return new Promise((resolve, reject) => {
|
|
76
80
|
if (existing) {
|
|
77
81
|
existing.props = props;
|
|
@@ -79,7 +83,7 @@ export class ModalManager {
|
|
|
79
83
|
existing.resolve = resolve;
|
|
80
84
|
existing.reject = reject;
|
|
81
85
|
} else {
|
|
82
|
-
this
|
|
86
|
+
this.modals.set(id, {
|
|
83
87
|
id,
|
|
84
88
|
component: markRaw(component),
|
|
85
89
|
props,
|
|
@@ -91,17 +95,18 @@ export class ModalManager {
|
|
|
91
95
|
});
|
|
92
96
|
}
|
|
93
97
|
#resolve(id, result) {
|
|
94
|
-
const modal = this
|
|
98
|
+
const modal = this.modals.get(id);
|
|
95
99
|
if (!modal)
|
|
96
100
|
return;
|
|
97
101
|
modal.opened = false;
|
|
98
102
|
modal.resolve?.(result);
|
|
99
103
|
}
|
|
100
104
|
#reject(id, reason) {
|
|
101
|
-
const modal = this
|
|
105
|
+
const modal = this.modals.get(id);
|
|
102
106
|
if (!modal)
|
|
103
107
|
return;
|
|
104
108
|
modal.opened = false;
|
|
105
109
|
modal.reject?.(reason);
|
|
106
110
|
}
|
|
107
111
|
}
|
|
112
|
+
export const $modals = markRaw(ModalManager.instance);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { $modals } from "./modal-manager";
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<template>
|
|
6
|
+
<ClientOnly>
|
|
7
|
+
<div id='nui-modals-root'>
|
|
8
|
+
<component
|
|
9
|
+
:is='entry.component'
|
|
10
|
+
v-for='[id, entry] in $modals.modals'
|
|
11
|
+
:key='id'
|
|
12
|
+
v-bind='entry.props'
|
|
13
|
+
/>
|
|
14
|
+
</div>
|
|
15
|
+
</ClientOnly>
|
|
16
|
+
</template>
|
|
@@ -21,8 +21,8 @@ id: string): {
|
|
|
21
21
|
*
|
|
22
22
|
* Setting to `true` reopens the modal, setting to `false` calls `reject`
|
|
23
23
|
*/
|
|
24
|
-
opened: import("vue").WritableComputedRef<
|
|
24
|
+
opened: import("vue").WritableComputedRef<boolean, boolean>;
|
|
25
25
|
/** closes the modal and resolves the promise */
|
|
26
|
-
resolve: (reason: Resolve) =>
|
|
27
|
-
reject: () =>
|
|
26
|
+
resolve: (reason: Resolve) => void;
|
|
27
|
+
reject: () => void;
|
|
28
28
|
};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { useNuxtApp } from "#app";
|
|
2
1
|
import { computed } from "vue";
|
|
2
|
+
import { $modals } from "./modal-manager.js";
|
|
3
3
|
export function useModal(id) {
|
|
4
|
-
const
|
|
5
|
-
const state = computed(() => manager.state(id));
|
|
4
|
+
const state = computed(() => $modals.state(id));
|
|
6
5
|
const opened = computed({
|
|
7
6
|
get: () => state.value?.opened,
|
|
8
|
-
set: (opened2) => opened2 ?
|
|
7
|
+
set: (opened2) => opened2 ? $modals.show(id, state.value.props) : $modals.reject(id, "cancel")
|
|
9
8
|
});
|
|
10
9
|
if (!state)
|
|
11
10
|
throw new Error(`Modal ${id} is not exist`);
|
|
@@ -17,7 +16,7 @@ export function useModal(id) {
|
|
|
17
16
|
*/
|
|
18
17
|
opened,
|
|
19
18
|
/** closes the modal and resolves the promise */
|
|
20
|
-
resolve: (reason) =>
|
|
21
|
-
reject: () =>
|
|
19
|
+
resolve: (reason) => $modals.resolve(id, reason),
|
|
20
|
+
reject: () => $modals.reject(id)
|
|
22
21
|
};
|
|
23
22
|
}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './_confirm-modal/index.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./_confirm-modal/index.js";
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
<script setup>
|
|
2
|
-
import { useNuxtApp } from "#app";
|
|
3
|
-
import { ClientOnly } from "#components";
|
|
4
|
-
import { computed } from "vue";
|
|
5
|
-
const modals = computed(() => useNuxtApp().$modals?.modals ?? []);
|
|
6
|
-
</script>
|
|
7
|
-
|
|
8
|
-
<template>
|
|
9
|
-
<ClientOnly>
|
|
10
|
-
<div id='nui-modals-root'>
|
|
11
|
-
<component
|
|
12
|
-
:is='entry.component'
|
|
13
|
-
v-for='[id, entry] in modals'
|
|
14
|
-
:key='id'
|
|
15
|
-
v-bind='entry.props'
|
|
16
|
-
/>
|
|
17
|
-
</div>
|
|
18
|
-
</ClientOnly>
|
|
19
|
-
</template>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { $modals } from './plugin.client.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { $modals } from "./plugin.client.js";
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ModalManager } from './modal-manager.js';
|
|
2
|
-
export declare const $modals: import("vue").Raw<ModalManager>;
|
|
3
|
-
declare const _default: import("#app").Plugin<{
|
|
4
|
-
modals: import("vue").Raw<ModalManager>;
|
|
5
|
-
}> & import("#app").ObjectPlugin<{
|
|
6
|
-
modals: import("vue").Raw<ModalManager>;
|
|
7
|
-
}>;
|
|
8
|
-
export default _default;
|
|
File without changes
|
|
File without changes
|