MCPcopy
hub / github.com/QwikDev/qwik / VirtualElementImpl

Class VirtualElementImpl

packages/qwik/src/core/render/dom/virtual-element.ts:130–334  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128export const VIRTUAL = ':virtual';
129
130export class VirtualElementImpl implements VirtualElement {
131 ownerDocument: Document;
132 _qc_: any = null;
133
134 readonly nodeType = 111 as const;
135 readonly localName = VIRTUAL;
136 readonly nodeName = VIRTUAL;
137
138 private $attributes$: Record<string, string>;
139 private $template$: HTMLTemplateElement;
140
141 constructor(
142 readonly open: Comment,
143 readonly close: Comment,
144 readonly isSvg: boolean
145 ) {
146 const doc = (this.ownerDocument = open.ownerDocument);
147 this.$template$ = createElement(doc, 'template', false) as HTMLTemplateElement;
148 this.$attributes$ = parseVirtualAttributes(open.data.slice(3));
149 assertTrue(open.data.startsWith('qv '), 'comment is not a qv');
150 (open as any)[VIRTUAL_SYMBOL] = this;
151 (close as any)[VIRTUAL_SYMBOL] = this;
152 seal(this);
153 }
154
155 insertBefore<T extends Node>(node: T, ref: Node | null): T {
156 const parent = this.parentElement;
157 if (parent) {
158 const ref2 = ref ? ref : this.close;
159 parent.insertBefore(node, ref2);
160 } else {
161 this.$template$.insertBefore(node, ref);
162 }
163 return node;
164 }
165
166 remove() {
167 const parent = this.parentElement;
168 if (parent) {
169 const ch = this.childNodes;
170 assertEqual(this.$template$.childElementCount, 0, 'children should be empty');
171 parent.removeChild(this.open);
172 for (let i = 0; i < ch.length; i++) {
173 this.$template$.appendChild(ch[i]);
174 }
175 parent.removeChild(this.close);
176 }
177 }
178
179 appendChild<T extends Node>(node: T): T {
180 return this.insertBefore(node, null);
181 }
182
183 insertBeforeTo(newParent: QwikElement, child: Node | null) {
184 // const ch = this.childNodes;
185 const ch = this.childNodes;
186 // TODO
187 // if (this.parentElement) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…