@dative-gpi/foundation-shared-components 1.1.9-sandbox-1 → 1.1.9-sandbox-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/composables/useDomRenderer.ts +32 -38
- package/package.json +4 -4
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import { h, render, getCurrentInstance, onBeforeUnmount, toValue, type Component, type MaybeRefOrGetter, watch } from "vue";
|
|
2
2
|
|
|
3
3
|
interface RenderHandle {
|
|
4
|
-
|
|
4
|
+
unsubscribe: () => void;
|
|
5
5
|
getElement: (style?: Partial<CSSStyleDeclaration>) => HTMLElement;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
interface
|
|
9
|
-
container: HTMLElement
|
|
8
|
+
interface Subscription {
|
|
9
|
+
container: HTMLElement;
|
|
10
10
|
mountPoint: HTMLElement;
|
|
11
|
-
stopWatching: (
|
|
11
|
+
stopWatching: () => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function destroySubscription(subscription: Subscription) {
|
|
15
|
+
subscription.stopWatching();
|
|
16
|
+
render(null, subscription.container);
|
|
17
|
+
subscription.container.remove();
|
|
18
|
+
subscription.mountPoint.remove();
|
|
12
19
|
}
|
|
13
20
|
|
|
14
21
|
export function useDomRenderer<TProps extends Record<string, any>>(component: Component<TProps>) {
|
|
@@ -19,12 +26,10 @@ export function useDomRenderer<TProps extends Record<string, any>>(component: Co
|
|
|
19
26
|
}
|
|
20
27
|
|
|
21
28
|
const appContext = instance.appContext;
|
|
22
|
-
const
|
|
29
|
+
const subscriptions = new Set<Subscription>();
|
|
23
30
|
|
|
24
|
-
const
|
|
25
|
-
const id = Symbol();
|
|
31
|
+
const subscribe = (getProps: MaybeRefOrGetter<TProps>, style?: Partial<CSSStyleDeclaration>): RenderHandle => {
|
|
26
32
|
const mountPoint = document.createElement("div");
|
|
27
|
-
Object.assign(mountPoint.style, style ?? {});
|
|
28
33
|
|
|
29
34
|
const container = document.createElement("div");
|
|
30
35
|
mountPoint.appendChild(container);
|
|
@@ -39,51 +44,40 @@ export function useDomRenderer<TProps extends Record<string, any>>(component: Co
|
|
|
39
44
|
{ immediate: true }
|
|
40
45
|
);
|
|
41
46
|
|
|
42
|
-
|
|
47
|
+
const subscription: Subscription = { container, mountPoint, stopWatching };
|
|
48
|
+
subscriptions.add(subscription);
|
|
43
49
|
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
if (!subscriber) {
|
|
50
|
+
const unsubscribe = () => {
|
|
51
|
+
if (!subscriptions.has(subscription)) {
|
|
47
52
|
return;
|
|
48
53
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
subscriber.stopWatching();
|
|
52
|
-
}
|
|
53
|
-
render(null, subscriber.container!);
|
|
54
|
-
subscriber.container!.remove();
|
|
55
|
-
subscriber.mountPoint.remove();
|
|
56
|
-
subscribers.delete(id);
|
|
54
|
+
destroySubscription(subscription);
|
|
55
|
+
subscriptions.delete(subscription);
|
|
57
56
|
};
|
|
58
57
|
|
|
59
58
|
const getElement = (newStyle?: Partial<CSSStyleDeclaration>): HTMLElement => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
throw new Error("This render handle has already been unmounted");
|
|
59
|
+
if (!subscriptions.has(subscription)) {
|
|
60
|
+
throw new Error("This render handle has already been unsubscribed");
|
|
63
61
|
}
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
mountPoint.style.cssText = "";
|
|
63
|
+
Object.assign(mountPoint.style, style ?? {}, newStyle ?? {});
|
|
64
|
+
return mountPoint;
|
|
66
65
|
};
|
|
67
66
|
|
|
68
|
-
return {
|
|
67
|
+
return { unsubscribe, getElement };
|
|
69
68
|
};
|
|
70
69
|
|
|
71
|
-
const
|
|
72
|
-
for (const
|
|
73
|
-
|
|
74
|
-
subscriber.stopWatching();
|
|
75
|
-
}
|
|
76
|
-
render(null, subscriber.container!);
|
|
77
|
-
subscriber.container!.remove();
|
|
78
|
-
subscriber.mountPoint.remove();
|
|
79
|
-
subscribers.delete(id);
|
|
70
|
+
const unsubscribeAll = () => {
|
|
71
|
+
for (const subscription of subscriptions) {
|
|
72
|
+
destroySubscription(subscription);
|
|
80
73
|
}
|
|
74
|
+
subscriptions.clear();
|
|
81
75
|
};
|
|
82
76
|
|
|
83
|
-
onBeforeUnmount(
|
|
77
|
+
onBeforeUnmount(unsubscribeAll);
|
|
84
78
|
|
|
85
79
|
return {
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
subscribe,
|
|
81
|
+
unsubscribeAll,
|
|
88
82
|
};
|
|
89
83
|
}
|
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.1.9-sandbox-
|
|
7
|
+
"version": "1.1.9-sandbox-2",
|
|
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.1.9-sandbox-
|
|
17
|
-
"@dative-gpi/foundation-shared-services": "1.1.9-sandbox-
|
|
16
|
+
"@dative-gpi/foundation-shared-domain": "1.1.9-sandbox-2",
|
|
17
|
+
"@dative-gpi/foundation-shared-services": "1.1.9-sandbox-2"
|
|
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": "a26ae1e0964030d75000054d021c1d45feadb98e"
|
|
42
42
|
}
|