@adobe-commerce/elsie 1.4.1-alpha101 → 1.4.1-alpha102
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 +1 -1
- package/src/lib/render.tsx +21 -7
package/package.json
CHANGED
package/src/lib/render.tsx
CHANGED
|
@@ -71,17 +71,21 @@ export class Render {
|
|
|
71
71
|
rootElement.innerHTML = '';
|
|
72
72
|
|
|
73
73
|
// clone the root element to initialize rendering on the background
|
|
74
|
-
const
|
|
74
|
+
const root = document.createElement('div');
|
|
75
75
|
|
|
76
76
|
// apply base design tokens and global styles to the root element
|
|
77
77
|
rootElement.classList.add('dropin-design');
|
|
78
|
+
rootElement.setAttribute('data-dropin-container', Component.name);
|
|
78
79
|
|
|
79
|
-
|
|
80
|
+
// store the virtual root element
|
|
81
|
+
(rootElement as any).__rootElement = root;
|
|
82
|
+
|
|
83
|
+
render(<Root next={state} />, root);
|
|
80
84
|
|
|
81
85
|
// API object to control the rendered component
|
|
82
86
|
const API: RenderAPI = {
|
|
83
87
|
remove: () => {
|
|
84
|
-
render(null,
|
|
88
|
+
render(null, root);
|
|
85
89
|
},
|
|
86
90
|
setProps: (cb: (prev: T) => T) => {
|
|
87
91
|
const next = cb(state.peek());
|
|
@@ -97,7 +101,7 @@ export class Render {
|
|
|
97
101
|
rootElement.classList.add('dropin-design');
|
|
98
102
|
|
|
99
103
|
// append the rendered component to the DOM only when all slots are resolved
|
|
100
|
-
rootElement.appendChild(
|
|
104
|
+
rootElement.appendChild(root.firstChild ?? root);
|
|
101
105
|
|
|
102
106
|
return resolve(API);
|
|
103
107
|
}
|
|
@@ -106,14 +110,24 @@ export class Render {
|
|
|
106
110
|
};
|
|
107
111
|
}
|
|
108
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Unmounts a container from a root element.
|
|
115
|
+
* @param rootElement - The root element to unmount the container from.
|
|
116
|
+
*/
|
|
117
|
+
static unmount(rootElement: HTMLElement) {
|
|
118
|
+
const root = (rootElement as any)?.__rootElement;
|
|
119
|
+
if (!root) throw new Error('Root element is not defined');
|
|
120
|
+
render(null, root);
|
|
121
|
+
}
|
|
122
|
+
|
|
109
123
|
/**
|
|
110
124
|
* UnRenders a component from a root element.
|
|
111
125
|
* @param rootElement - The root element to unmount the component from.
|
|
112
|
-
* @deprecated Use `remove` method from the returned object of the `mount` method instead.
|
|
126
|
+
* @deprecated Use `remove` method from the returned object of the `mount` method instead or `unmount` method from the `Render` class.
|
|
113
127
|
*/
|
|
114
128
|
unmount(rootElement: HTMLElement) {
|
|
115
129
|
if (!rootElement) throw new Error('Root element is not defined');
|
|
116
|
-
rootElement.firstChild?.remove();
|
|
130
|
+
rootElement.firstChild?.remove();
|
|
117
131
|
}
|
|
118
132
|
|
|
119
133
|
/**
|
|
@@ -135,4 +149,4 @@ export class Render {
|
|
|
135
149
|
{ ...options }
|
|
136
150
|
);
|
|
137
151
|
}
|
|
138
|
-
}
|
|
152
|
+
}
|