contents-popup-redtombo 1.0.1 → 1.0.2
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/README.md +75 -0
- package/components/DeleteSong.vue +3 -0
- package/components/EditSong.vue +1 -1
- package/components/componentPopup.vue +42 -0
- package/components/{popup.vue → componentPopup2.vue} +2 -4
- package/components/{PopupContents.vue → componentPopup3.vue} +1 -11
- package/composables/useComponent.ts +23 -0
- package/composables/usePopup.ts +11 -4
- package/package.json +8 -14
- package/module.ts +0 -14
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Nuxt Minimal Starter
|
|
2
|
+
|
|
3
|
+
Look at the [Nuxt documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
Make sure to install dependencies:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# npm
|
|
11
|
+
npm install
|
|
12
|
+
|
|
13
|
+
# pnpm
|
|
14
|
+
pnpm install
|
|
15
|
+
|
|
16
|
+
# yarn
|
|
17
|
+
yarn install
|
|
18
|
+
|
|
19
|
+
# bun
|
|
20
|
+
bun install
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Development Server
|
|
24
|
+
|
|
25
|
+
Start the development server on `http://localhost:3000`:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# npm
|
|
29
|
+
npm run dev
|
|
30
|
+
|
|
31
|
+
# pnpm
|
|
32
|
+
pnpm dev
|
|
33
|
+
|
|
34
|
+
# yarn
|
|
35
|
+
yarn dev
|
|
36
|
+
|
|
37
|
+
# bun
|
|
38
|
+
bun run dev
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Production
|
|
42
|
+
|
|
43
|
+
Build the application for production:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# npm
|
|
47
|
+
npm run build
|
|
48
|
+
|
|
49
|
+
# pnpm
|
|
50
|
+
pnpm build
|
|
51
|
+
|
|
52
|
+
# yarn
|
|
53
|
+
yarn build
|
|
54
|
+
|
|
55
|
+
# bun
|
|
56
|
+
bun run build
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Locally preview production build:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# npm
|
|
63
|
+
npm run preview
|
|
64
|
+
|
|
65
|
+
# pnpm
|
|
66
|
+
pnpm preview
|
|
67
|
+
|
|
68
|
+
# yarn
|
|
69
|
+
yarn preview
|
|
70
|
+
|
|
71
|
+
# bun
|
|
72
|
+
bun run preview
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.
|
package/components/EditSong.vue
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { toRefs, watch } from "vue";
|
|
3
|
+
import { usePopup } from "../composables/usePopup";
|
|
4
|
+
import type { Component } from "vue";
|
|
5
|
+
|
|
6
|
+
const { state, openPopup, changePopup, initPopup } = usePopup();
|
|
7
|
+
const { popupVisible } = toRefs(state);
|
|
8
|
+
|
|
9
|
+
// プロパティ定義と取得
|
|
10
|
+
const props = defineProps<{
|
|
11
|
+
component: string;
|
|
12
|
+
componentList: Record<string, Component>;
|
|
13
|
+
click: (variable?: any) => void;
|
|
14
|
+
}>();
|
|
15
|
+
|
|
16
|
+
// 必要な props をリアクティブに扱うため分割代入
|
|
17
|
+
const { component, componentList } = toRefs(props);
|
|
18
|
+
|
|
19
|
+
// 初期化処理
|
|
20
|
+
initPopup(componentList.value);
|
|
21
|
+
|
|
22
|
+
// `component` が変更された場合にポップアップを開く
|
|
23
|
+
watch(
|
|
24
|
+
component, // 監視対象としてリアクティブな `component` を指定
|
|
25
|
+
(newComponent: string) => {
|
|
26
|
+
changePopup(newComponent); // ポップアップを変更する
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
function handleClick() {
|
|
31
|
+
// ボタンがクリックされたら親の関数を呼び出す
|
|
32
|
+
props.click();
|
|
33
|
+
openPopup(props.component)
|
|
34
|
+
}
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<template>
|
|
38
|
+
<div>
|
|
39
|
+
<button @click="handleClick();" class="btn btn-primary">更新</button>
|
|
40
|
+
<componentPopup2 v-if="popupVisible" />
|
|
41
|
+
</div>
|
|
42
|
+
</template>
|
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
import { toRefs } from "vue";
|
|
3
3
|
import { usePopup } from "../composables/usePopup";
|
|
4
4
|
|
|
5
|
-
import PopupContents from "
|
|
6
|
-
|
|
5
|
+
import PopupContents from "./componentPopup3.vue";
|
|
7
6
|
const { state } = usePopup();
|
|
8
7
|
const { componentErrorMessage } = toRefs(state);
|
|
9
8
|
</script>
|
|
10
9
|
|
|
11
|
-
|
|
12
10
|
<template>
|
|
13
11
|
<Teleport to="body">
|
|
14
12
|
<div
|
|
@@ -30,7 +28,7 @@ const { componentErrorMessage } = toRefs(state);
|
|
|
30
28
|
エラーが発生しました<br/>
|
|
31
29
|
{{ componentErrorMessage }}
|
|
32
30
|
</p>
|
|
33
|
-
<
|
|
31
|
+
<componentPopup3 v-else/>
|
|
34
32
|
</div>
|
|
35
33
|
</div>
|
|
36
34
|
</div>
|
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { toRefs } from "vue";
|
|
3
3
|
import { usePopup } from "../composables/usePopup";
|
|
4
|
-
import EditSong from "~/components/EditSong.vue";
|
|
5
4
|
|
|
6
5
|
// EditSongを登録
|
|
7
|
-
const { state, closePopup
|
|
6
|
+
const { state, closePopup } = usePopup();
|
|
8
7
|
const { isLoading,currentComponent } = toRefs(state);
|
|
9
|
-
|
|
10
|
-
const component: string = 'EditSong';
|
|
11
|
-
const componentList: Record<string, Component> = {
|
|
12
|
-
"EditSong": EditSong
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
initPopup(componentList);
|
|
16
8
|
</script>
|
|
17
9
|
|
|
18
10
|
<template>
|
|
@@ -26,8 +18,6 @@ initPopup(componentList);
|
|
|
26
18
|
</p>
|
|
27
19
|
<div v-show="!isLoading">
|
|
28
20
|
<div>
|
|
29
|
-
<!-- EditSongの表示 -->
|
|
30
|
-
<!-- <EditSong v-if="currentComponent === 'EditSong'"/> -->
|
|
31
21
|
<component :is="currentComponent" />
|
|
32
22
|
</div>
|
|
33
23
|
</div>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
interface State {
|
|
2
|
+
component: string; //コンポーネント
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
// グローバルな状態管理
|
|
6
|
+
const state = reactive<State>({
|
|
7
|
+
component: "EditSong",
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export function useComponent() {
|
|
11
|
+
function changeComponent(): void {
|
|
12
|
+
if (state.component === "EditSong") {
|
|
13
|
+
state.component = "DeleteSong";
|
|
14
|
+
} else {
|
|
15
|
+
state.component = "EditSong";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
changeComponent,
|
|
21
|
+
state,
|
|
22
|
+
};
|
|
23
|
+
}
|
package/composables/usePopup.ts
CHANGED
|
@@ -27,10 +27,17 @@ export function usePopup() {
|
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
//
|
|
30
|
+
// ポップアップを開く関数
|
|
31
31
|
function openPopup(component: string): void {
|
|
32
32
|
state.popupVisible = true;
|
|
33
33
|
|
|
34
|
+
changePopup(component);
|
|
35
|
+
|
|
36
|
+
state.isLoading = false; // ローディングを終了
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 指定されたコンポーネントをセットする関数
|
|
40
|
+
function changePopup(component: string): void {
|
|
34
41
|
if (component in state.componentList) {
|
|
35
42
|
state.currentComponent = markRaw(state.componentList[component]);
|
|
36
43
|
state.componentErrorMessage = ""; // エラーメッセージをリセット
|
|
@@ -39,15 +46,14 @@ export function usePopup() {
|
|
|
39
46
|
console.error(errorMessage);
|
|
40
47
|
state.componentErrorMessage = errorMessage;
|
|
41
48
|
}
|
|
42
|
-
|
|
43
|
-
state.isLoading = false; // ローディングを終了
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
// ポップアップを閉じる関数
|
|
47
52
|
function closePopup(): void {
|
|
48
|
-
state.popupVisible = false;
|
|
49
53
|
state.currentComponent = null; // 現在のコンポーネントをリセット
|
|
50
54
|
state.componentErrorMessage = ""; // エラーメッセージをリセット
|
|
55
|
+
|
|
56
|
+
state.popupVisible = false;
|
|
51
57
|
}
|
|
52
58
|
|
|
53
59
|
// 必要なものを返却
|
|
@@ -56,5 +62,6 @@ export function usePopup() {
|
|
|
56
62
|
initPopup,
|
|
57
63
|
openPopup,
|
|
58
64
|
closePopup,
|
|
65
|
+
changePopup,
|
|
59
66
|
};
|
|
60
67
|
}
|
package/package.json
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "contents-popup-redtombo",
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
"build": "nuxt build",
|
|
11
|
-
"dev": "nuxt dev",
|
|
12
|
-
"install": "nuxt prepare"
|
|
13
|
-
},
|
|
14
|
-
"dependencies": {
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "中のコンポーネントを変更できるポップアップ",
|
|
5
|
+
"main": "./module.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./module.ts"
|
|
8
|
+
},
|
|
9
|
+
"peerDependencies": {
|
|
15
10
|
"bootstrap": "^5.0.0",
|
|
16
|
-
"nuxt": "^3.0.0"
|
|
17
|
-
"nuxt-lodash": "^2.0.0"
|
|
11
|
+
"nuxt": "^3.0.0"
|
|
18
12
|
},
|
|
19
13
|
"files": [
|
|
20
14
|
"module.ts",
|
package/module.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { defineNuxtModule } from '@nuxt/kit'
|
|
2
|
-
import { resolve } from 'path'
|
|
3
|
-
|
|
4
|
-
export default defineNuxtModule({
|
|
5
|
-
setup(_, nuxt) {
|
|
6
|
-
// コンポーネントディレクトリを追加
|
|
7
|
-
nuxt.hook('components:dirs', (dirs) => {
|
|
8
|
-
dirs.push({
|
|
9
|
-
path: resolve(__dirname, 'components'), // モジュール内のコンポーネントを登録
|
|
10
|
-
pathPrefix: false,
|
|
11
|
-
})
|
|
12
|
-
})
|
|
13
|
-
},
|
|
14
|
-
})
|