@dative-gpi/foundation-shared-components 1.0.193-value-data-composable → 1.0.194-dynamic-vue-app
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/composables/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./useBreakpoints";
|
|
|
5
5
|
export * from "./useColors";
|
|
6
6
|
export * from "./useCountUp";
|
|
7
7
|
export * from "./useDebounce";
|
|
8
|
+
export * from "./useDynamicVueApp";
|
|
8
9
|
export * from "./useElementVisibility";
|
|
9
10
|
export * from "./useMapLayers";
|
|
10
11
|
export * from "./useRules";
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { uuidv4 } from "@dative-gpi/bones-ui";
|
|
2
|
+
import { createApp, nextTick, onBeforeUnmount, type App, type Component } from "vue";
|
|
3
|
+
|
|
4
|
+
export function useDynamicVueApp<TProps extends Record<string, any>>(
|
|
5
|
+
component: Component,
|
|
6
|
+
options?: { registerPlugins?: (app: App) => void }
|
|
7
|
+
) {
|
|
8
|
+
let app: App | null = null;
|
|
9
|
+
let isMounting = false;
|
|
10
|
+
|
|
11
|
+
const id = uuidv4();
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const mount = async (props: TProps): Promise<void> => {
|
|
15
|
+
if (isMounting) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
isMounting = true;
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
await nextTick();
|
|
23
|
+
|
|
24
|
+
const mountPoint = document.getElementById(id);
|
|
25
|
+
if (!mountPoint) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
unmount();
|
|
30
|
+
|
|
31
|
+
app = createApp(component, props);
|
|
32
|
+
options?.registerPlugins?.(app);
|
|
33
|
+
app.mount(mountPoint);
|
|
34
|
+
} finally {
|
|
35
|
+
isMounting = false;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const unmount = () => {
|
|
40
|
+
if (!app) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
app.unmount();
|
|
44
|
+
app = null;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const sanitizeStyle = (style?: string): string => {
|
|
48
|
+
if (!style) {
|
|
49
|
+
return "";
|
|
50
|
+
}
|
|
51
|
+
return style
|
|
52
|
+
.replace(/"/g, """)
|
|
53
|
+
.replace(/</g, "<")
|
|
54
|
+
.replace(/>/g, ">");
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const getHtml = (style?: string) => {
|
|
58
|
+
const safeStyle = sanitizeStyle(style);
|
|
59
|
+
const styleAttribute = safeStyle ? ` style="${safeStyle}"` : "";
|
|
60
|
+
return `<div id="${id}"${styleAttribute}></div>`;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
onBeforeUnmount(() => {
|
|
64
|
+
unmount();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return { mount, unmount, getHtml };
|
|
68
|
+
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"url": "https://github.com/Dative-GPI/foundation-shared-ui.git"
|
|
5
5
|
},
|
|
6
6
|
"sideEffects": false,
|
|
7
|
-
"version": "1.0.
|
|
7
|
+
"version": "1.0.194-dynamic-vue-app",
|
|
8
8
|
"description": "",
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"author": "",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@dative-gpi/foundation-shared-domain": "1.0.
|
|
17
|
-
"@dative-gpi/foundation-shared-services": "1.0.
|
|
16
|
+
"@dative-gpi/foundation-shared-domain": "1.0.194-dynamic-vue-app",
|
|
17
|
+
"@dative-gpi/foundation-shared-services": "1.0.194-dynamic-vue-app"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"@dative-gpi/bones-ui": "^1.0.0",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"sass": "1.71.1",
|
|
39
39
|
"sass-loader": "13.3.2"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "15437d51d163b21dd5eaf10397da1108571f4b1f"
|
|
42
42
|
}
|