@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.
@@ -7322,34 +7322,6 @@ class VComponentDirective {
7322
7322
  get onUnmounted() {
7323
7323
  return undefined;
7324
7324
  }
7325
- /**
7326
- * Clones the component's template and returns the root element.
7327
- * @returns The cloned root HTMLElement of the component.
7328
- * @throws Error if the component or its template is not found.
7329
- */
7330
- cloneNode() {
7331
- // Get component definition from the application's component registry
7332
- const component = this.#vNode.vApplication.componentRegistry.get(this.#componentId);
7333
- if (!component) {
7334
- throw new Error(`Component '${this.#componentId}' not found in registry`);
7335
- }
7336
- // Get template element
7337
- const finalTemplateID = component.templateID || component.id;
7338
- const templateElement = document.querySelector(`#${finalTemplateID}`);
7339
- if (!templateElement || !(templateElement instanceof HTMLTemplateElement)) {
7340
- throw new Error(`Template element '#${finalTemplateID}' not found`);
7341
- }
7342
- // Clone template content
7343
- const fragment = templateElement.content.cloneNode(true);
7344
- const childNodes = Array.from(fragment.childNodes);
7345
- // Find the first element node
7346
- for (const node of childNodes) {
7347
- if (node.nodeType === Node.ELEMENT_NODE) {
7348
- return node;
7349
- }
7350
- }
7351
- throw new Error(`No element found in template '#${finalTemplateID}'`);
7352
- }
7353
7325
  /**
7354
7326
  * @inheritdoc
7355
7327
  */
@@ -7375,6 +7347,9 @@ class VComponentDirective {
7375
7347
  // Already rendered, no action needed
7376
7348
  return;
7377
7349
  }
7350
+ // Clone the component's template and replace the original node
7351
+ const clone = this.#cloneNode();
7352
+ this.#vNode.anchorNode?.parentNode?.insertBefore(clone, this.#vNode.anchorNode.nextSibling);
7378
7353
  // Get properties from :options or :options.component directive
7379
7354
  let properties = {};
7380
7355
  const optionsDirective = this.#vNode.directiveManager?.optionsDirective('component');
@@ -7399,7 +7374,35 @@ class VComponentDirective {
7399
7374
  const instance = component.createInstance(properties);
7400
7375
  // Create and mount child application using the parent application's registries
7401
7376
  this.#componentApp = this.#vNode.vApplication.createChildApp(instance);
7402
- this.#componentApp.mount(this.#vNode.node);
7377
+ this.#componentApp.mount(clone);
7378
+ }
7379
+ /**
7380
+ * Clones the component's template and returns the root element.
7381
+ * @returns The cloned root HTMLElement of the component.
7382
+ * @throws Error if the component or its template is not found.
7383
+ */
7384
+ #cloneNode() {
7385
+ // Get component definition from the application's component registry
7386
+ const component = this.#vNode.vApplication.componentRegistry.get(this.#componentId);
7387
+ if (!component) {
7388
+ throw new Error(`Component '${this.#componentId}' not found in registry`);
7389
+ }
7390
+ // Get template element
7391
+ const finalTemplateID = component.templateID || component.id;
7392
+ const templateElement = document.querySelector(`#${finalTemplateID}`);
7393
+ if (!templateElement || !(templateElement instanceof HTMLTemplateElement)) {
7394
+ throw new Error(`Template element '#${finalTemplateID}' not found`);
7395
+ }
7396
+ // Clone template content
7397
+ const fragment = templateElement.content.cloneNode(true);
7398
+ const childNodes = Array.from(fragment.childNodes);
7399
+ // Find the first element node
7400
+ for (const node of childNodes) {
7401
+ if (node.nodeType === Node.ELEMENT_NODE) {
7402
+ return node;
7403
+ }
7404
+ }
7405
+ throw new Error(`No element found in template '#${finalTemplateID}'`);
7403
7406
  }
7404
7407
  }
7405
7408
 
@@ -7734,11 +7737,6 @@ class VDirectiveManager {
7734
7737
  * The keys are directive names (e.g., 'options', 'options.intersection').
7735
7738
  */
7736
7739
  #optionsDirectives = {};
7737
- /**
7738
- * The v-component directive associated with this node, if any.
7739
- * This may be undefined if there is no v-component directive.
7740
- */
7741
- #componentDirective;
7742
7740
  constructor(vNode) {
7743
7741
  // Directives can only be associated with element nodes
7744
7742
  if (vNode.nodeType !== Node.ELEMENT_NODE) {
@@ -7796,13 +7794,6 @@ class VDirectiveManager {
7796
7794
  get keyDirective() {
7797
7795
  return this.#keyDirective;
7798
7796
  }
7799
- /**
7800
- * Gets the v-component directive associated with this node, if any.
7801
- * This may be undefined if there is no v-component directive.
7802
- */
7803
- get componentDirective() {
7804
- return this.#componentDirective;
7805
- }
7806
7797
  /**
7807
7798
  * Gets the VBindDirective for options specific to the given directive name.
7808
7799
  * Searches in order: `:options.{directive}` -> `:options`
@@ -7892,10 +7883,6 @@ class VDirectiveManager {
7892
7883
  this.#optionsDirectives[attrName] = bindDirective;
7893
7884
  }
7894
7885
  }
7895
- // If this is a v-component directive, store it separately
7896
- if (directive.name === StandardDirectiveName.V_COMPONENT) {
7897
- this.#componentDirective = directive;
7898
- }
7899
7886
  }
7900
7887
  }
7901
7888
  // Sort directives by priority: v-for > v-if > v-else-if > v-else > v-show > others
@@ -8825,8 +8812,17 @@ class VConditionalDirective {
8825
8812
  // Already rendered, no action needed
8826
8813
  return;
8827
8814
  }
8828
- this.#renderedVNode = this.#cloneTemplate();
8829
- this.#vNode.anchorNode?.parentNode?.insertBefore(this.#renderedVNode.node, this.#vNode.anchorNode.nextSibling);
8815
+ // Clone the original node and create a new VNode for it
8816
+ const clone = this.#cloneNode();
8817
+ // Insert the cloned node after the anchor node, or as a child of the parent if no anchor
8818
+ this.#vNode.anchorNode?.parentNode?.insertBefore(clone, this.#vNode.anchorNode.nextSibling);
8819
+ // Create a new VNode for the cloned element
8820
+ const vNode = new VNode({
8821
+ node: clone,
8822
+ vApplication: this.#vNode.vApplication,
8823
+ parentVNode: this.#vNode.parentVNode
8824
+ });
8825
+ this.#renderedVNode = vNode;
8830
8826
  this.#renderedVNode.forceUpdate();
8831
8827
  }
8832
8828
  /**
@@ -8845,25 +8841,13 @@ class VConditionalDirective {
8845
8841
  this.#renderedVNode = undefined;
8846
8842
  }
8847
8843
  /**
8848
- * Clones the template element and creates a new VNode for the cloned element.
8844
+ * Clones the original node of the directive's virtual node.
8845
+ * This is used to create a new instance of the node for rendering.
8846
+ * @returns The cloned HTMLElement.
8849
8847
  */
8850
- #cloneTemplate() {
8851
- // Clone the original element
8852
- let clone;
8853
- if (this.vNode.directiveManager?.componentDirective) {
8854
- clone = this.vNode.directiveManager.componentDirective.cloneNode();
8855
- }
8856
- else {
8857
- const element = this.#vNode.node;
8858
- clone = element.cloneNode(true);
8859
- }
8860
- // Create a new VNode for the cloned element
8861
- const vNode = new VNode({
8862
- node: clone,
8863
- vApplication: this.#vNode.vApplication,
8864
- parentVNode: this.#vNode.parentVNode
8865
- });
8866
- return vNode;
8848
+ #cloneNode() {
8849
+ const element = this.#vNode.node;
8850
+ return element.cloneNode(true);
8867
8851
  }
8868
8852
  /**
8869
8853
  * Creates a function to evaluate the directive's condition.
@@ -9203,15 +9187,36 @@ class VForDirective {
9203
9187
  let vNode = this.#renderedItems.get(key);
9204
9188
  if (!vNode) {
9205
9189
  // Create new item
9206
- vNode = this.#cloneTemplate(context);
9207
- newRenderedItems.set(key, vNode);
9190
+ const clone = this.#cloneNode();
9208
9191
  // Insert after previous node
9209
9192
  if (prevNode.nextSibling) {
9210
- parent.insertBefore(vNode.node, prevNode.nextSibling);
9193
+ parent.insertBefore(clone, prevNode.nextSibling);
9211
9194
  }
9212
9195
  else {
9213
- parent.appendChild(vNode.node);
9196
+ parent.appendChild(clone);
9197
+ }
9198
+ // Prepare identifiers for the item
9199
+ this.#itemName;
9200
+ this.#indexName;
9201
+ // Create bindings for this iteration
9202
+ const bindings = new VBindings({
9203
+ parent: this.#vNode.bindings
9204
+ });
9205
+ if (this.#itemName) {
9206
+ bindings.set(this.#itemName, context.item);
9214
9207
  }
9208
+ if (this.#indexName) {
9209
+ bindings.set(this.#indexName, context.index);
9210
+ }
9211
+ // Create a new VNode for the cloned element
9212
+ vNode = new VNode({
9213
+ node: clone,
9214
+ vApplication: this.#vNode.vApplication,
9215
+ parentVNode: this.#vNode.parentVNode,
9216
+ bindings,
9217
+ dependentIdentifiers: [`${this.#sourceName}[${context.index}]`]
9218
+ });
9219
+ newRenderedItems.set(key, vNode);
9215
9220
  vNode.forceUpdate();
9216
9221
  }
9217
9222
  else {
@@ -9287,40 +9292,14 @@ class VForDirective {
9287
9292
  };
9288
9293
  }
9289
9294
  /**
9290
- * Clone template element for each iteration and create a new VNode
9295
+ * Clones the original node of the directive's virtual node.
9296
+ * This is used to create a new instance of the node for rendering.
9297
+ * @returns The cloned HTMLElement.
9291
9298
  */
9292
- #cloneTemplate(context) {
9299
+ #cloneNode() {
9293
9300
  // Clone the original element
9294
- let clone;
9295
- if (this.vNode.directiveManager?.componentDirective) {
9296
- clone = this.vNode.directiveManager.componentDirective.cloneNode();
9297
- }
9298
- else {
9299
- const element = this.#vNode.node;
9300
- clone = element.cloneNode(true);
9301
- }
9302
- // Prepare identifiers for the item
9303
- this.#itemName;
9304
- this.#indexName;
9305
- // Create bindings for this iteration
9306
- const bindings = new VBindings({
9307
- parent: this.#vNode.bindings
9308
- });
9309
- if (this.#itemName) {
9310
- bindings.set(this.#itemName, context.item);
9311
- }
9312
- if (this.#indexName) {
9313
- bindings.set(this.#indexName, context.index);
9314
- }
9315
- // Create a new VNode for the cloned element
9316
- const vNode = new VNode({
9317
- node: clone,
9318
- vApplication: this.#vNode.vApplication,
9319
- parentVNode: this.#vNode.parentVNode,
9320
- bindings,
9321
- dependentIdentifiers: [`${this.#sourceName}[${context.index}]`]
9322
- });
9323
- return vNode;
9301
+ const element = this.#vNode.node;
9302
+ return element.cloneNode(true);
9324
9303
  }
9325
9304
  /**
9326
9305
  * Update bindings for an existing item