@bikariya/modals 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025-present KazariEX
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,5 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+
3
+ declare const _default: _nuxt_schema.NuxtModule<_nuxt_schema.ModuleOptions, _nuxt_schema.ModuleOptions, false>;
4
+
5
+ export { _default as default };
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@bikariya/modals",
3
+ "configKey": "modals",
4
+ "version": "0.0.1",
5
+ "builder": {
6
+ "@nuxt/module-builder": "1.0.2",
7
+ "unbuild": "3.6.1"
8
+ }
9
+ }
@@ -0,0 +1,34 @@
1
+ import { defineNuxtModule, createResolver, addImportsDir, addComponent, addTemplate } from '@nuxt/kit';
2
+
3
+ const name = "@bikariya/modals";
4
+ const packageJson = {
5
+ name: name};
6
+
7
+ const module$1 = defineNuxtModule({
8
+ meta: {
9
+ name: packageJson.name,
10
+ configKey: "modals"
11
+ },
12
+ moduleDependencies: {
13
+ "@bikariya/core": {}
14
+ },
15
+ setup(options) {
16
+ const resolver = createResolver(import.meta.url);
17
+ addImportsDir(resolver.resolve("runtime/stores"));
18
+ addComponent({
19
+ name: "BikariyaModals",
20
+ filePath: resolver.resolve("runtime/modals.vue")
21
+ });
22
+ addTemplate({
23
+ filename: "nuxt-modal.mjs",
24
+ getContents: () => (
25
+ /* TS */
26
+ `
27
+ export const overlayClass = \`${options.overlayClass}\`;
28
+ `.trimStart()
29
+ )
30
+ });
31
+ }
32
+ });
33
+
34
+ export { module$1 as default };
@@ -0,0 +1,3 @@
1
+ declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
+ declare const _default: typeof __VLS_export;
3
+ export default _default;
@@ -0,0 +1,19 @@
1
+ <script setup>
2
+ import { storeToRefs, useModalStore } from "#imports";
3
+ const modalStore = useModalStore();
4
+ const { modals } = storeToRefs(modalStore);
5
+ </script>
6
+
7
+ <template>
8
+ <template v-for="{ vnode, zIndex, isOpening, close } in modals" :key="zIndex">
9
+ <transition>
10
+ <div
11
+ v-if="isOpening.value"
12
+ class="bikariya-overlay"
13
+ :style="{ zIndex: zIndex - 1 }"
14
+ @click="close.value"
15
+ ></div>
16
+ </transition>
17
+ <component :is="vnode.value" :is-opening="isOpening.value" :style="{ zIndex }"/>
18
+ </template>
19
+ </template>
@@ -0,0 +1,3 @@
1
+ declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
+ declare const _default: typeof __VLS_export;
3
+ export default _default;
@@ -0,0 +1,33 @@
1
+ import { type ComputedRef, type Ref, type VNode } from "#imports";
2
+ interface ModalContext {
3
+ vnode: ComputedRef<VNode>;
4
+ zIndex: number;
5
+ duration: number;
6
+ isOpening: Ref<boolean>;
7
+ close: ComputedRef<() => void>;
8
+ }
9
+ interface UseModalOptions {
10
+ duration?: number;
11
+ immediate?: boolean;
12
+ unique?: boolean;
13
+ }
14
+ export declare const useModalStore: import("pinia").StoreDefinition<"modal", Pick<{
15
+ modals: import("vue").ShallowReactive<ModalContext[]>;
16
+ use: (render: () => VNode, options?: UseModalOptions) => {
17
+ open: () => void;
18
+ close: () => Promise<void>;
19
+ };
20
+ }, "modals">, Pick<{
21
+ modals: import("vue").ShallowReactive<ModalContext[]>;
22
+ use: (render: () => VNode, options?: UseModalOptions) => {
23
+ open: () => void;
24
+ close: () => Promise<void>;
25
+ };
26
+ }, never>, Pick<{
27
+ modals: import("vue").ShallowReactive<ModalContext[]>;
28
+ use: (render: () => VNode, options?: UseModalOptions) => {
29
+ open: () => void;
30
+ close: () => Promise<void>;
31
+ };
32
+ }, "use">>;
33
+ export {};
@@ -0,0 +1,59 @@
1
+ import { promiseTimeout } from "@vueuse/core";
2
+ import { computed, defineStore, ref, shallowReactive, watchEffect } from "#imports";
3
+ export const useModalStore = defineStore("modal", () => {
4
+ const modals = shallowReactive([]);
5
+ function use(render, options = {}) {
6
+ const {
7
+ duration = 400,
8
+ immediate = false,
9
+ unique = false
10
+ } = options;
11
+ let ctx;
12
+ const isOpening = ref(false);
13
+ immediate && open();
14
+ function open() {
15
+ if (unique && indexOf() !== -1) {
16
+ return;
17
+ }
18
+ const vnode = computed(render);
19
+ watchEffect(() => {
20
+ vnode.value.props = {
21
+ onClose: close,
22
+ onVnodeMounted() {
23
+ isOpening.value = true;
24
+ },
25
+ ...vnode.value.props
26
+ };
27
+ });
28
+ const last = modals.at(-1);
29
+ const zIndex = (last?.zIndex ?? 510) + 2;
30
+ ctx = {
31
+ vnode,
32
+ zIndex,
33
+ duration,
34
+ isOpening,
35
+ close: computed(() => vnode.value.props?.onClose)
36
+ };
37
+ modals.push(ctx);
38
+ }
39
+ async function close() {
40
+ isOpening.value = false;
41
+ await promiseTimeout(duration);
42
+ const i = indexOf();
43
+ if (i !== -1) {
44
+ modals.splice(i, 1);
45
+ }
46
+ }
47
+ function indexOf() {
48
+ return modals.indexOf(ctx);
49
+ }
50
+ return {
51
+ open,
52
+ close
53
+ };
54
+ }
55
+ return {
56
+ modals,
57
+ use
58
+ };
59
+ });
@@ -0,0 +1,7 @@
1
+ import type { NuxtModule } from '@nuxt/schema'
2
+
3
+ import type { default as Module } from './module.mjs'
4
+
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
+
7
+ export { default } from './module.mjs'
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@bikariya/modals",
3
+ "type": "module",
4
+ "version": "0.0.1",
5
+ "description": "",
6
+ "author": "KazariEX",
7
+ "license": "MIT",
8
+ "repository": "KazariEX/bikariya",
9
+ "keywords": [],
10
+ "exports": {
11
+ ".": "./dist/module.mjs"
12
+ },
13
+ "main": "./dist/module.mjs",
14
+ "types": "./dist/module.d.mts",
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "dependencies": {
19
+ "@bikariya/core": "",
20
+ "@nuxt/kit": "^4.2.2"
21
+ },
22
+ "scripts": {
23
+ "build": "nuxt-module-build build",
24
+ "dev": "nuxt-module-build build --stub",
25
+ "dev:prepare": "nuxt-module-build prepare"
26
+ }
27
+ }