contents-popup-redtombo 1.4.2 → 1.4.4

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/package.json CHANGED
@@ -1,17 +1,21 @@
1
1
  {
2
2
  "name": "contents-popup-redtombo",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "description": "ポップアップの中のComponentsを動的に切り替えることができるポップアップ",
5
5
  "type": "module",
6
+ "main": "./dist/module.cjs",
7
+ "module": "./dist/module.mjs",
8
+ "types": "./dist/module.d.ts",
6
9
  "exports": {
7
10
  ".": {
11
+ "types": "./dist/module.d.ts",
8
12
  "import": "./dist/module.mjs",
9
- "require": "./dist/module.cjs",
10
- "types": "./dist/module.d.ts"
13
+ "require": "./dist/module.cjs"
11
14
  }
12
15
  },
13
16
  "files": [
14
17
  "dist",
18
+ "runtime",
15
19
  "README.md",
16
20
  "CHANGELOG.md"
17
21
  ],
@@ -19,7 +23,7 @@
19
23
  "dev": "nuxt dev",
20
24
  "preview": "nuxt preview",
21
25
  "build": "unbuild",
22
- "prepublishOnly": "npm run build"
26
+ "prepack": "npm run build"
23
27
  },
24
28
  "peerDependencies": {
25
29
  "bootstrap": "^5.0.0",
@@ -27,6 +31,7 @@
27
31
  },
28
32
  "devDependencies": {
29
33
  "@nuxt/cli": "^3.29.3",
34
+ "@types/node": "^24.9.2",
30
35
  "nuxt": "^4.2.0",
31
36
  "typescript": "^5.9.3",
32
37
  "unbuild": "^2.0.0"
@@ -0,0 +1,46 @@
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
+ buttonName: string;
12
+ component: string;
13
+ componentList: Record<string, Component>;
14
+ click?: (variable?: any) => void;
15
+ }>();
16
+
17
+ // 必要な props をリアクティブに扱うため分割代入
18
+ const { component, componentList } = toRefs(props);
19
+
20
+ // 初期化処理
21
+ initPopup(componentList.value);
22
+
23
+ // `component` が変更された場合にポップアップを開く
24
+ watch(
25
+ component, // 監視対象としてリアクティブな `component` を指定
26
+ (newComponent: string) => {
27
+ changePopup(newComponent); // ポップアップを変更する
28
+ }
29
+ );
30
+
31
+ function handleClick() {
32
+ // 親コンポーネントの関数が存在するなら、
33
+ // 親コンポーネントの関数を呼び出す。
34
+ if(props.click){
35
+ props.click();
36
+ }
37
+ openPopup(props.component)
38
+ }
39
+ </script>
40
+
41
+ <template>
42
+ <div>
43
+ <button @click="handleClick();" class="btn btn-primary">{{ props.buttonName }}</button>
44
+ <componentPopup2 v-if="popupVisible" />
45
+ </div>
46
+ </template>
@@ -0,0 +1,69 @@
1
+ <script setup lang="ts">
2
+ import { toRefs } from "vue";
3
+ import { usePopup } from "../composables/usePopup";
4
+
5
+ import PopupContents from "./componentPopup3.vue";
6
+ const { state } = usePopup();
7
+ const { componentErrorMessage } = toRefs(state);
8
+ </script>
9
+
10
+ <template>
11
+ <Teleport to="body">
12
+ <div
13
+ class="modal show fade d-flex align-items-center justify-content-center"
14
+ tabindex="-1"
15
+ style="display: block"
16
+ >
17
+ <div class="modal-dialog custom-size" @click.stop>
18
+ <div
19
+ class="modal-content p-3"
20
+ :class="{ 'modal-danger': componentErrorMessage }"
21
+ >
22
+ <div class="modal-body">
23
+ <!-- エラーメッセージ表示 -->
24
+ <p
25
+ v-if="componentErrorMessage"
26
+ class="text-danger"
27
+ >
28
+ エラーが発生しました<br/>
29
+ {{ componentErrorMessage }}
30
+ </p>
31
+ <componentPopup3 v-else/>
32
+ </div>
33
+ </div>
34
+ </div>
35
+ </div>
36
+ </Teleport>
37
+ </template>
38
+
39
+ <style scoped>
40
+ .modal.show {
41
+ background: rgba(0, 0, 0, 0.5);
42
+ }
43
+
44
+ .modal-content {
45
+ border-radius: 8px;
46
+ }
47
+
48
+ .custom-size {
49
+ width: 1080px !important; /* 任意の幅を指定 */
50
+ max-width: none !important; /* 最大幅の制限を解除 */
51
+ }
52
+
53
+ .modal.show {
54
+ display: flex !important; /* Flexbox有効 */
55
+ align-items: center !important; /* 縦中央揃え */
56
+ justify-content: center !important; /* 横中央揃え */
57
+ }
58
+
59
+ .modal-danger {
60
+ background-color: var(
61
+ --bs-danger-bg-subtle,
62
+ #f8d7da
63
+ ); /* Bootstrapのalert-dangerの背景色 */
64
+ color: var(
65
+ --bs-danger-text,
66
+ #842029
67
+ ); /* Bootstrapのalert-dangerのテキスト色 */
68
+ }
69
+ </style>
@@ -0,0 +1,24 @@
1
+ <script setup lang="ts">
2
+ import { toRefs } from "vue";
3
+ import { usePopup } from "../composables/usePopup";
4
+
5
+ // EditSongを登録
6
+ const { state, closePopup } = usePopup();
7
+ const { isLoading,currentComponent } = toRefs(state);
8
+ </script>
9
+
10
+ <template>
11
+ <div class="d-flex justify-content-end mb-4">
12
+ <button @click="closePopup()" class="btn btn-close" type="button"></button>
13
+ </div>
14
+
15
+ <!-- currentComponentでコンポーネントの表示を切り替える。 -->
16
+ <p v-show="isLoading" class="text-center text-primary">
17
+ データ取得中...
18
+ </p>
19
+ <div v-show="!isLoading">
20
+ <div>
21
+ <component :is="currentComponent" />
22
+ </div>
23
+ </div>
24
+ </template>
@@ -0,0 +1,67 @@
1
+ import { reactive, markRaw } from "vue";
2
+ import type { Component } from "vue";
3
+
4
+ interface State {
5
+ componentErrorMessage: string; // コンポーネントエラーメッセージ
6
+ popupVisible: boolean; // ポップアップが表示中かどうか
7
+ isLoading: boolean; // ローディング中かどうか
8
+ currentComponent: Component | null; // 現在のコンポーネント
9
+ componentList: Record<string, Component>; // 使用可能なコンポーネントのリスト
10
+ }
11
+
12
+ // グローバルな状態管理
13
+ const state = reactive<State>({
14
+ componentErrorMessage: "",
15
+ popupVisible: false,
16
+ isLoading: true,
17
+ currentComponent: null,
18
+ componentList: {},
19
+ });
20
+
21
+ // `usePopup` composable 関数
22
+ export function usePopup() {
23
+ // ポップアップの初期化
24
+ function initPopup(componentList: Record<string, Component>): void {
25
+ state.componentList = Object.fromEntries(
26
+ Object.entries(componentList).map(([key, component]) => [key, markRaw(component)])
27
+ );
28
+ }
29
+
30
+ // ポップアップを開く関数
31
+ function openPopup(component: string): void {
32
+ state.popupVisible = true;
33
+
34
+ changePopup(component);
35
+
36
+ state.isLoading = false; // ローディングを終了
37
+ }
38
+
39
+ // 指定されたコンポーネントをセットする関数
40
+ function changePopup(component: string): void {
41
+ if (component in state.componentList) {
42
+ state.currentComponent = markRaw(state.componentList[component]);
43
+ state.componentErrorMessage = ""; // エラーメッセージをリセット
44
+ } else {
45
+ const errorMessage = `選択されたコンポーネントが無効です: ${component}`;
46
+ console.error(errorMessage);
47
+ state.componentErrorMessage = errorMessage;
48
+ }
49
+ }
50
+
51
+ // ポップアップを閉じる関数
52
+ function closePopup(): void {
53
+ state.currentComponent = null; // 現在のコンポーネントをリセット
54
+ state.componentErrorMessage = ""; // エラーメッセージをリセット
55
+
56
+ state.popupVisible = false;
57
+ }
58
+
59
+ // 必要なものを返却
60
+ return {
61
+ state,
62
+ initPopup,
63
+ openPopup,
64
+ closePopup,
65
+ changePopup,
66
+ };
67
+ }