@mintjamsinc/ichigojs 0.1.17 → 0.1.19

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.
@@ -7328,34 +7328,6 @@
7328
7328
  get onUnmounted() {
7329
7329
  return undefined;
7330
7330
  }
7331
- /**
7332
- * Clones the component's template and returns the root element.
7333
- * @returns The cloned root HTMLElement of the component.
7334
- * @throws Error if the component or its template is not found.
7335
- */
7336
- cloneNode() {
7337
- // Get component definition from the application's component registry
7338
- const component = this.#vNode.vApplication.componentRegistry.get(this.#componentId);
7339
- if (!component) {
7340
- throw new Error(`Component '${this.#componentId}' not found in registry`);
7341
- }
7342
- // Get template element
7343
- const finalTemplateID = component.templateID || component.id;
7344
- const templateElement = document.querySelector(`#${finalTemplateID}`);
7345
- if (!templateElement || !(templateElement instanceof HTMLTemplateElement)) {
7346
- throw new Error(`Template element '#${finalTemplateID}' not found`);
7347
- }
7348
- // Clone template content
7349
- const fragment = templateElement.content.cloneNode(true);
7350
- const childNodes = Array.from(fragment.childNodes);
7351
- // Find the first element node
7352
- for (const node of childNodes) {
7353
- if (node.nodeType === Node.ELEMENT_NODE) {
7354
- return node;
7355
- }
7356
- }
7357
- throw new Error(`No element found in template '#${finalTemplateID}'`);
7358
- }
7359
7331
  /**
7360
7332
  * @inheritdoc
7361
7333
  */
@@ -7381,6 +7353,9 @@
7381
7353
  // Already rendered, no action needed
7382
7354
  return;
7383
7355
  }
7356
+ // Clone the component's template and replace the original node
7357
+ const clone = this.#cloneNode();
7358
+ this.#vNode.anchorNode?.parentNode?.insertBefore(clone, this.#vNode.anchorNode.nextSibling);
7384
7359
  // Get properties from :options or :options.component directive
7385
7360
  let properties = {};
7386
7361
  const optionsDirective = this.#vNode.directiveManager?.optionsDirective('component');
@@ -7405,7 +7380,35 @@
7405
7380
  const instance = component.createInstance(properties);
7406
7381
  // Create and mount child application using the parent application's registries
7407
7382
  this.#componentApp = this.#vNode.vApplication.createChildApp(instance);
7408
- this.#componentApp.mount(this.#vNode.node);
7383
+ this.#componentApp.mount(clone);
7384
+ }
7385
+ /**
7386
+ * Clones the component's template and returns the root element.
7387
+ * @returns The cloned root HTMLElement of the component.
7388
+ * @throws Error if the component or its template is not found.
7389
+ */
7390
+ #cloneNode() {
7391
+ // Get component definition from the application's component registry
7392
+ const component = this.#vNode.vApplication.componentRegistry.get(this.#componentId);
7393
+ if (!component) {
7394
+ throw new Error(`Component '${this.#componentId}' not found in registry`);
7395
+ }
7396
+ // Get template element
7397
+ const finalTemplateID = component.templateID || component.id;
7398
+ const templateElement = document.querySelector(`#${finalTemplateID}`);
7399
+ if (!templateElement || !(templateElement instanceof HTMLTemplateElement)) {
7400
+ throw new Error(`Template element '#${finalTemplateID}' not found`);
7401
+ }
7402
+ // Clone template content
7403
+ const fragment = templateElement.content.cloneNode(true);
7404
+ const childNodes = Array.from(fragment.childNodes);
7405
+ // Find the first element node
7406
+ for (const node of childNodes) {
7407
+ if (node.nodeType === Node.ELEMENT_NODE) {
7408
+ return node;
7409
+ }
7410
+ }
7411
+ throw new Error(`No element found in template '#${finalTemplateID}'`);
7409
7412
  }
7410
7413
  }
7411
7414
 
@@ -7740,11 +7743,6 @@
7740
7743
  * The keys are directive names (e.g., 'options', 'options.intersection').
7741
7744
  */
7742
7745
  #optionsDirectives = {};
7743
- /**
7744
- * The v-component directive associated with this node, if any.
7745
- * This may be undefined if there is no v-component directive.
7746
- */
7747
- #componentDirective;
7748
7746
  constructor(vNode) {
7749
7747
  // Directives can only be associated with element nodes
7750
7748
  if (vNode.nodeType !== Node.ELEMENT_NODE) {
@@ -7802,13 +7800,6 @@
7802
7800
  get keyDirective() {
7803
7801
  return this.#keyDirective;
7804
7802
  }
7805
- /**
7806
- * Gets the v-component directive associated with this node, if any.
7807
- * This may be undefined if there is no v-component directive.
7808
- */
7809
- get componentDirective() {
7810
- return this.#componentDirective;
7811
- }
7812
7803
  /**
7813
7804
  * Gets the VBindDirective for options specific to the given directive name.
7814
7805
  * Searches in order: `:options.{directive}` -> `:options`
@@ -7898,10 +7889,6 @@
7898
7889
  this.#optionsDirectives[attrName] = bindDirective;
7899
7890
  }
7900
7891
  }
7901
- // If this is a v-component directive, store it separately
7902
- if (directive.name === StandardDirectiveName.V_COMPONENT) {
7903
- this.#componentDirective = directive;
7904
- }
7905
7892
  }
7906
7893
  }
7907
7894
  // Sort directives by priority: v-for > v-if > v-else-if > v-else > v-show > others
@@ -8831,8 +8818,17 @@
8831
8818
  // Already rendered, no action needed
8832
8819
  return;
8833
8820
  }
8834
- this.#renderedVNode = this.#cloneTemplate();
8835
- this.#vNode.anchorNode?.parentNode?.insertBefore(this.#renderedVNode.node, this.#vNode.anchorNode.nextSibling);
8821
+ // Clone the original node and create a new VNode for it
8822
+ const clone = this.#cloneNode();
8823
+ // Insert the cloned node after the anchor node, or as a child of the parent if no anchor
8824
+ this.#vNode.anchorNode?.parentNode?.insertBefore(clone, this.#vNode.anchorNode.nextSibling);
8825
+ // Create a new VNode for the cloned element
8826
+ const vNode = new VNode({
8827
+ node: clone,
8828
+ vApplication: this.#vNode.vApplication,
8829
+ parentVNode: this.#vNode.parentVNode
8830
+ });
8831
+ this.#renderedVNode = vNode;
8836
8832
  this.#renderedVNode.forceUpdate();
8837
8833
  }
8838
8834
  /**
@@ -8851,25 +8847,13 @@
8851
8847
  this.#renderedVNode = undefined;
8852
8848
  }
8853
8849
  /**
8854
- * Clones the template element and creates a new VNode for the cloned element.
8850
+ * Clones the original node of the directive's virtual node.
8851
+ * This is used to create a new instance of the node for rendering.
8852
+ * @returns The cloned HTMLElement.
8855
8853
  */
8856
- #cloneTemplate() {
8857
- // Clone the original element
8858
- let clone;
8859
- if (this.vNode.directiveManager?.componentDirective) {
8860
- clone = this.vNode.directiveManager.componentDirective.cloneNode();
8861
- }
8862
- else {
8863
- const element = this.#vNode.node;
8864
- clone = element.cloneNode(true);
8865
- }
8866
- // Create a new VNode for the cloned element
8867
- const vNode = new VNode({
8868
- node: clone,
8869
- vApplication: this.#vNode.vApplication,
8870
- parentVNode: this.#vNode.parentVNode
8871
- });
8872
- return vNode;
8854
+ #cloneNode() {
8855
+ const element = this.#vNode.node;
8856
+ return element.cloneNode(true);
8873
8857
  }
8874
8858
  /**
8875
8859
  * Creates a function to evaluate the directive's condition.
@@ -9209,15 +9193,36 @@
9209
9193
  let vNode = this.#renderedItems.get(key);
9210
9194
  if (!vNode) {
9211
9195
  // Create new item
9212
- vNode = this.#cloneTemplate(context);
9213
- newRenderedItems.set(key, vNode);
9196
+ const clone = this.#cloneNode();
9214
9197
  // Insert after previous node
9215
9198
  if (prevNode.nextSibling) {
9216
- parent.insertBefore(vNode.node, prevNode.nextSibling);
9199
+ parent.insertBefore(clone, prevNode.nextSibling);
9217
9200
  }
9218
9201
  else {
9219
- parent.appendChild(vNode.node);
9202
+ parent.appendChild(clone);
9203
+ }
9204
+ // Prepare identifiers for the item
9205
+ this.#itemName;
9206
+ this.#indexName;
9207
+ // Create bindings for this iteration
9208
+ const bindings = new VBindings({
9209
+ parent: this.#vNode.bindings
9210
+ });
9211
+ if (this.#itemName) {
9212
+ bindings.set(this.#itemName, context.item);
9220
9213
  }
9214
+ if (this.#indexName) {
9215
+ bindings.set(this.#indexName, context.index);
9216
+ }
9217
+ // Create a new VNode for the cloned element
9218
+ vNode = new VNode({
9219
+ node: clone,
9220
+ vApplication: this.#vNode.vApplication,
9221
+ parentVNode: this.#vNode.parentVNode,
9222
+ bindings,
9223
+ dependentIdentifiers: [`${this.#sourceName}[${context.index}]`]
9224
+ });
9225
+ newRenderedItems.set(key, vNode);
9221
9226
  vNode.forceUpdate();
9222
9227
  }
9223
9228
  else {
@@ -9293,40 +9298,14 @@
9293
9298
  };
9294
9299
  }
9295
9300
  /**
9296
- * Clone template element for each iteration and create a new VNode
9301
+ * Clones the original node of the directive's virtual node.
9302
+ * This is used to create a new instance of the node for rendering.
9303
+ * @returns The cloned HTMLElement.
9297
9304
  */
9298
- #cloneTemplate(context) {
9305
+ #cloneNode() {
9299
9306
  // Clone the original element
9300
- let clone;
9301
- if (this.vNode.directiveManager?.componentDirective) {
9302
- clone = this.vNode.directiveManager.componentDirective.cloneNode();
9303
- }
9304
- else {
9305
- const element = this.#vNode.node;
9306
- clone = element.cloneNode(true);
9307
- }
9308
- // Prepare identifiers for the item
9309
- this.#itemName;
9310
- this.#indexName;
9311
- // Create bindings for this iteration
9312
- const bindings = new VBindings({
9313
- parent: this.#vNode.bindings
9314
- });
9315
- if (this.#itemName) {
9316
- bindings.set(this.#itemName, context.item);
9317
- }
9318
- if (this.#indexName) {
9319
- bindings.set(this.#indexName, context.index);
9320
- }
9321
- // Create a new VNode for the cloned element
9322
- const vNode = new VNode({
9323
- node: clone,
9324
- vApplication: this.#vNode.vApplication,
9325
- parentVNode: this.#vNode.parentVNode,
9326
- bindings,
9327
- dependentIdentifiers: [`${this.#sourceName}[${context.index}]`]
9328
- });
9329
- return vNode;
9307
+ const element = this.#vNode.node;
9308
+ return element.cloneNode(true);
9330
9309
  }
9331
9310
  /**
9332
9311
  * Update bindings for an existing item