MCPcopy Create free account
hub / github.com/stenciljs/core / patchSlotInsertAdjacentHTML

Function patchSlotInsertAdjacentHTML

src/runtime/dom-extras.ts:209–231  ·  view source on GitHub ↗
(HostElementPrototype: HTMLElement)

Source from the content-addressed store, hash-verified

207 * @param HostElementPrototype the `Element` to be patched
208 */
209export const patchSlotInsertAdjacentHTML = (HostElementPrototype: HTMLElement) => {
210 if ((HostElementPrototype as any).__insertAdjacentHTML) return;
211 const originalInsertAdjacentHtml = HostElementPrototype.insertAdjacentHTML;
212
213 HostElementPrototype.insertAdjacentHTML = function (this: d.HostElement, position: InsertPosition, text: string) {
214 if (position !== 'afterbegin' && position !== 'beforeend') {
215 return originalInsertAdjacentHtml.call(this, position, text);
216 }
217 const container = this.ownerDocument.createElement('_');
218 let node: d.RenderNode;
219 container.innerHTML = text;
220
221 if (position === 'afterbegin') {
222 while ((node = container.firstChild as d.RenderNode)) {
223 this.prepend(node);
224 }
225 } else if (position === 'beforeend') {
226 while ((node = container.firstChild as d.RenderNode)) {
227 this.append(node);
228 }
229 }
230 };
231};
232
233/**
234 * Patches the `insertAdjacentText` method for a slotted node inside a scoped component. Specifically,

Callers 1

patchPseudoShadowDomFunction · 0.85

Calls 3

createElementMethod · 0.80
prependMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected