contents-popup-redtombo 1.0.0 → 1.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.
@@ -0,0 +1,60 @@
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
+ if (component in state.componentList) {
35
+ state.currentComponent = markRaw(state.componentList[component]);
36
+ state.componentErrorMessage = ""; // エラーメッセージをリセット
37
+ } else {
38
+ const errorMessage = `選択されたコンポーネントが無効です: ${component}`;
39
+ console.error(errorMessage);
40
+ state.componentErrorMessage = errorMessage;
41
+ }
42
+
43
+ state.isLoading = false; // ローディングを終了
44
+ }
45
+
46
+ // ポップアップを閉じる関数
47
+ function closePopup(): void {
48
+ state.popupVisible = false;
49
+ state.currentComponent = null; // 現在のコンポーネントをリセット
50
+ state.componentErrorMessage = ""; // エラーメッセージをリセット
51
+ }
52
+
53
+ // 必要なものを返却
54
+ return {
55
+ state,
56
+ initPopup,
57
+ openPopup,
58
+ closePopup,
59
+ };
60
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contents-popup-redtombo",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "ポップアップのコンテンツを切り替える",
5
5
  "main": "./module.ts",
6
6
  "exports": {
@@ -18,6 +18,7 @@
18
18
  },
19
19
  "files": [
20
20
  "module.ts",
21
- "components"
21
+ "components",
22
+ "composables"
22
23
  ]
23
24
  }