@bikariya/modals
Advanced tools
| import { type ComputedRef, type Ref, type VNode } from "#imports"; | ||
| interface ModalContext { | ||
| vnode: ComputedRef<VNode>; | ||
| zIndex: number; | ||
| duration: number; | ||
| open: Ref<boolean>; | ||
| close: ComputedRef<() => void>; | ||
| } | ||
| type ModalStatus = "closed" | "open" | "closing"; | ||
| interface UseModalOptions { | ||
| duration?: number; | ||
| immediate?: boolean; | ||
| unique?: boolean; | ||
| } | ||
| export declare const useModalStore: import("pinia").StoreDefinition<"modal", Pick<{ | ||
| modals: import("vue").ShallowReactive<ModalContext[]>; | ||
| use: (render: () => VNode, options?: UseModalOptions) => { | ||
| open: () => void; | ||
| close: () => Promise<void>; | ||
| status: Ref<ModalStatus, ModalStatus>; | ||
| }; | ||
| }, "modals">, Pick<{ | ||
| modals: import("vue").ShallowReactive<ModalContext[]>; | ||
| use: (render: () => VNode, options?: UseModalOptions) => { | ||
| open: () => void; | ||
| close: () => Promise<void>; | ||
| status: Ref<ModalStatus, ModalStatus>; | ||
| }; | ||
| }, never>, Pick<{ | ||
| modals: import("vue").ShallowReactive<ModalContext[]>; | ||
| use: (render: () => VNode, options?: UseModalOptions) => { | ||
| open: () => void; | ||
| close: () => Promise<void>; | ||
| status: Ref<ModalStatus, ModalStatus>; | ||
| }; | ||
| }, "use">>; | ||
| export {}; |
| import { promiseTimeout } from "@vueuse/core"; | ||
| import { computed, defineStore, ref, shallowReactive, watchEffect } from "#imports"; | ||
| export const useModalStore = defineStore("modal", () => { | ||
| const modals = shallowReactive([]); | ||
| function use(render, options = {}) { | ||
| const { | ||
| duration = 400, | ||
| immediate = false, | ||
| unique = false | ||
| } = options; | ||
| let ctx; | ||
| const status = ref("closed"); | ||
| immediate && open(); | ||
| function open() { | ||
| if (unique && indexOf() !== -1) { | ||
| return; | ||
| } | ||
| const vnode = computed(render); | ||
| watchEffect(() => { | ||
| vnode.value.props = { | ||
| onClose: close, | ||
| onVnodeMounted() { | ||
| status.value = "open"; | ||
| }, | ||
| ...vnode.value.props | ||
| }; | ||
| }); | ||
| const last = modals.at(-1); | ||
| const zIndex = (last?.zIndex ?? 510) + 2; | ||
| ctx = { | ||
| vnode, | ||
| zIndex, | ||
| duration, | ||
| open: computed(() => status.value === "open"), | ||
| close: computed(() => vnode.value.props?.onClose) | ||
| }; | ||
| modals.push(ctx); | ||
| } | ||
| async function close() { | ||
| status.value = "closing"; | ||
| await promiseTimeout(duration); | ||
| status.value = "closed"; | ||
| const i = indexOf(); | ||
| if (i !== -1) { | ||
| modals.splice(i, 1); | ||
| } | ||
| } | ||
| function indexOf() { | ||
| return modals.indexOf(ctx); | ||
| } | ||
| return { | ||
| open, | ||
| close, | ||
| status | ||
| }; | ||
| } | ||
| return { | ||
| modals, | ||
| use | ||
| }; | ||
| }); |
+1
-1
| { | ||
| "name": "@bikariya/modals", | ||
| "configKey": "modals", | ||
| "version": "0.0.4", | ||
| "version": "0.0.5", | ||
| "builder": { | ||
@@ -6,0 +6,0 @@ "@nuxt/module-builder": "1.0.2", |
+7
-2
@@ -1,2 +0,2 @@ | ||
| import { defineNuxtModule, createResolver, addImportsDir, addComponent } from '@nuxt/kit'; | ||
| import { defineNuxtModule, createResolver, addImportsSources, addComponent } from '@nuxt/kit'; | ||
@@ -17,3 +17,8 @@ const name = "@bikariya/modals"; | ||
| const resolver = createResolver(import.meta.url); | ||
| addImportsDir(resolver.resolve("runtime/stores")); | ||
| addImportsSources({ | ||
| from: resolver.resolve("runtime/store"), | ||
| imports: [ | ||
| "useModalStore" | ||
| ] | ||
| }); | ||
| addComponent({ | ||
@@ -20,0 +25,0 @@ name: "BikariyaModals", |
@@ -8,6 +8,6 @@ <script setup> | ||
| <template> | ||
| <template v-for="{ vnode, zIndex, isOpening, close } in modals" :key="zIndex"> | ||
| <template v-for="{ vnode, zIndex, open, close } in modals" :key="zIndex"> | ||
| <transition> | ||
| <div | ||
| v-if="isOpening.value" | ||
| v-if="open.value" | ||
| class="bikariya-overlay" | ||
@@ -18,4 +18,4 @@ :style="{ zIndex: zIndex - 1 }" | ||
| </transition> | ||
| <component :is="vnode.value" :is-opening="isOpening.value" :style="{ zIndex }"/> | ||
| <component :is="vnode.value" :open="open.value" :style="{ zIndex }"/> | ||
| </template> | ||
| </template> |
+1
-1
| { | ||
| "name": "@bikariya/modals", | ||
| "type": "module", | ||
| "version": "0.0.4", | ||
| "version": "0.0.5", | ||
| "description": "Bikariya modals for Nuxt", | ||
@@ -6,0 +6,0 @@ "author": "KazariEX", |
+2
-2
@@ -36,3 +36,3 @@ # @bikariya/modals | ||
| defineProps<{ | ||
| isOpening?: boolean; | ||
| open?: boolean; | ||
| }>(); | ||
@@ -47,3 +47,3 @@ | ||
| <transition> | ||
| <div v-if="isOpening"> | ||
| <div v-if="open"> | ||
| <span>I'm a modal.</span> | ||
@@ -50,0 +50,0 @@ <button @click="$emit(`close`)">Close</button> |
| import { type ComputedRef, type Ref, type VNode } from "#imports"; | ||
| interface ModalContext { | ||
| vnode: ComputedRef<VNode>; | ||
| zIndex: number; | ||
| duration: number; | ||
| isOpening: Ref<boolean>; | ||
| close: ComputedRef<() => void>; | ||
| } | ||
| interface UseModalOptions { | ||
| duration?: number; | ||
| immediate?: boolean; | ||
| unique?: boolean; | ||
| } | ||
| export declare const useModalStore: import("pinia").StoreDefinition<"modal", Pick<{ | ||
| modals: import("vue").ShallowReactive<ModalContext[]>; | ||
| use: (render: () => VNode, options?: UseModalOptions) => { | ||
| open: () => void; | ||
| close: () => Promise<void>; | ||
| }; | ||
| }, "modals">, Pick<{ | ||
| modals: import("vue").ShallowReactive<ModalContext[]>; | ||
| use: (render: () => VNode, options?: UseModalOptions) => { | ||
| open: () => void; | ||
| close: () => Promise<void>; | ||
| }; | ||
| }, never>, Pick<{ | ||
| modals: import("vue").ShallowReactive<ModalContext[]>; | ||
| use: (render: () => VNode, options?: UseModalOptions) => { | ||
| open: () => void; | ||
| close: () => Promise<void>; | ||
| }; | ||
| }, "use">>; | ||
| export {}; |
| import { promiseTimeout } from "@vueuse/core"; | ||
| import { computed, defineStore, ref, shallowReactive, watchEffect } from "#imports"; | ||
| export const useModalStore = defineStore("modal", () => { | ||
| const modals = shallowReactive([]); | ||
| function use(render, options = {}) { | ||
| const { | ||
| duration = 400, | ||
| immediate = false, | ||
| unique = false | ||
| } = options; | ||
| let ctx; | ||
| const isOpening = ref(false); | ||
| immediate && open(); | ||
| function open() { | ||
| if (unique && indexOf() !== -1) { | ||
| return; | ||
| } | ||
| const vnode = computed(render); | ||
| watchEffect(() => { | ||
| vnode.value.props = { | ||
| onClose: close, | ||
| onVnodeMounted() { | ||
| isOpening.value = true; | ||
| }, | ||
| ...vnode.value.props | ||
| }; | ||
| }); | ||
| const last = modals.at(-1); | ||
| const zIndex = (last?.zIndex ?? 510) + 2; | ||
| ctx = { | ||
| vnode, | ||
| zIndex, | ||
| duration, | ||
| isOpening, | ||
| close: computed(() => vnode.value.props?.onClose) | ||
| }; | ||
| modals.push(ctx); | ||
| } | ||
| async function close() { | ||
| isOpening.value = false; | ||
| await promiseTimeout(duration); | ||
| const i = indexOf(); | ||
| if (i !== -1) { | ||
| modals.splice(i, 1); | ||
| } | ||
| } | ||
| function indexOf() { | ||
| return modals.indexOf(ctx); | ||
| } | ||
| return { | ||
| open, | ||
| close | ||
| }; | ||
| } | ||
| return { | ||
| modals, | ||
| use | ||
| }; | ||
| }); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
8063
4.04%141
8.46%1
Infinity%