@dative-gpi/foundation-shared-components 1.0.194-sandbox-4 → 1.0.194-sandbox-5

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.
@@ -49,7 +49,7 @@ export default {
49
49
  required: false
50
50
  },
51
51
  html: {
52
- type: String,
52
+ type: [String, HTMLElement] as PropType<string | HTMLElement>,
53
53
  required: false
54
54
  }
55
55
  },
@@ -1,11 +1,10 @@
1
- import { uuidv4 } from "@dative-gpi/bones-ui";
2
- import { h, render, nextTick, getCurrentInstance, onBeforeUnmount, type Component, type VNode } from "vue";
1
+ import { h, render, getCurrentInstance, onBeforeUnmount, type Component, type VNode } from "vue";
3
2
 
4
- export function useDynamicVNode<TProps extends Record<string, any>>(component: Component) {
5
- const id = uuidv4();
3
+ export function useDynamicVNode<TProps extends Record<string, any>>(component: Component<TProps>) {
6
4
 
7
5
  let vnode: VNode | null = null;
8
6
  let container: HTMLElement | null = null;
7
+ let mountPoint: HTMLElement | null = null;
9
8
 
10
9
  const instance = getCurrentInstance();
11
10
  if (!instance) {
@@ -15,11 +14,8 @@ export function useDynamicVNode<TProps extends Record<string, any>>(component: C
15
14
  const appContext = instance.appContext;
16
15
 
17
16
  const mount = async (props: TProps) => {
18
- await nextTick();
19
-
20
- const mountPoint = document.getElementById(id);
21
17
  if (!mountPoint) {
22
- return;
18
+ throw new Error(`You must call getElement() first to create the mount point`);
23
19
  }
24
20
 
25
21
  if (!container) {
@@ -36,19 +32,16 @@ export function useDynamicVNode<TProps extends Record<string, any>>(component: C
36
32
  const unmount = () => {
37
33
  if (container) {
38
34
  render(null, container);
35
+ container.remove();
39
36
  }
40
37
  vnode = null;
41
38
  container = null;
42
39
  };
43
40
 
44
- const sanitizeStyle = (style?: string): string =>
45
- style
46
- ? style.replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;")
47
- : "";
48
-
49
- const getHtml = (style?: string) => {
50
- const safeStyle = sanitizeStyle(style);
51
- return `<div id="${id}"${safeStyle ? ` style="${safeStyle}"` : ""}></div>`;
41
+ const getElement = (style?: Partial<CSSStyleDeclaration>): HTMLElement => {
42
+ mountPoint = document.createElement("div");
43
+ Object.assign(mountPoint.style, style ?? {});
44
+ return mountPoint;
52
45
  };
53
46
 
54
47
  onBeforeUnmount(unmount);
@@ -56,6 +49,6 @@ export function useDynamicVNode<TProps extends Record<string, any>>(component: C
56
49
  return {
57
50
  mount,
58
51
  unmount,
59
- getHtml
52
+ getElement
60
53
  };
61
54
  }
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.194-sandbox-4",
7
+ "version": "1.0.194-sandbox-5",
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.194-sandbox-4",
17
- "@dative-gpi/foundation-shared-services": "1.0.194-sandbox-4"
16
+ "@dative-gpi/foundation-shared-domain": "1.0.194-sandbox-5",
17
+ "@dative-gpi/foundation-shared-services": "1.0.194-sandbox-5"
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": "5344244153200caa3426444b2d3f7ed84f46679c"
41
+ "gitHead": "479e28515d44e7c9602a4717c8eceb44fed607a1"
42
42
  }