@mintjamsinc/ichigojs 0.1.12 → 0.1.14

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.
@@ -7222,14 +7222,6 @@ class VComponentDirective {
7222
7222
  * The virtual node to which this directive is applied.
7223
7223
  */
7224
7224
  #vNode;
7225
- /**
7226
- * The component ID expression.
7227
- */
7228
- #expression;
7229
- /**
7230
- * Whether the component ID is static (not reactive).
7231
- */
7232
- #isStatic = false;
7233
7225
  /**
7234
7226
  * The component ID to render.
7235
7227
  */
@@ -7244,10 +7236,7 @@ class VComponentDirective {
7244
7236
  #isActivated = false;
7245
7237
  constructor(context) {
7246
7238
  this.#vNode = context.vNode;
7247
- this.#expression = context.attribute.value;
7248
- // Check for .static modifier
7249
- const attrName = context.attribute.name;
7250
- this.#isStatic = attrName.includes('.static');
7239
+ this.#componentId = context.attribute.value.trim();
7251
7240
  // Remove the directive attribute from the element
7252
7241
  this.#vNode.node.removeAttribute(context.attribute.name);
7253
7242
  }
@@ -7286,7 +7275,7 @@ class VComponentDirective {
7286
7275
  },
7287
7276
  applyToDOM: () => {
7288
7277
  if (!this.#isActivated) {
7289
- this.renderComponent();
7278
+ this.#renderComponent();
7290
7279
  }
7291
7280
  }
7292
7281
  };
@@ -7332,7 +7321,7 @@ class VComponentDirective {
7332
7321
  * @inheritdoc
7333
7322
  */
7334
7323
  get onUnmount() {
7335
- return () => this.cleanupComponent();
7324
+ return () => this.#cleanupComponent();
7336
7325
  }
7337
7326
  /**
7338
7327
  * @inheritdoc
@@ -7340,26 +7329,39 @@ class VComponentDirective {
7340
7329
  get onUnmounted() {
7341
7330
  return undefined;
7342
7331
  }
7332
+ cloneNode() {
7333
+ // Get component definition from the application's component registry
7334
+ const component = this.#vNode.vApplication.componentRegistry.get(this.#componentId);
7335
+ if (!component) {
7336
+ throw new Error(`Component '${this.#componentId}' not found in registry`);
7337
+ }
7338
+ // Get template element
7339
+ const finalTemplateID = component.templateID || component.id;
7340
+ const templateElement = document.querySelector(`#${finalTemplateID}`);
7341
+ if (!templateElement || !(templateElement instanceof HTMLTemplateElement)) {
7342
+ throw new Error(`Template element '#${finalTemplateID}' not found`);
7343
+ }
7344
+ // Clone template content
7345
+ const fragment = templateElement.content.cloneNode(true);
7346
+ const childNodes = Array.from(fragment.childNodes);
7347
+ // Find the first element node
7348
+ for (const node of childNodes) {
7349
+ if (node.nodeType === Node.ELEMENT_NODE) {
7350
+ return node;
7351
+ }
7352
+ }
7353
+ throw new Error(`No element found in template '#${finalTemplateID}'`);
7354
+ }
7343
7355
  /**
7344
7356
  * @inheritdoc
7345
7357
  */
7346
7358
  destroy() {
7347
- this.cleanupComponent();
7359
+ this.#cleanupComponent();
7348
7360
  }
7349
7361
  /**
7350
7362
  * Renders the component.
7351
7363
  */
7352
- renderComponent() {
7353
- const element = this.#vNode.node;
7354
- if (!element) {
7355
- return;
7356
- }
7357
- // For now, only support static component IDs
7358
- const componentId = this.#expression.trim();
7359
- if (!componentId) {
7360
- console.warn(`Component ID is empty for v-component directive`);
7361
- return;
7362
- }
7364
+ #renderComponent() {
7363
7365
  // Get properties from :options or :options.component directive
7364
7366
  let properties = {};
7365
7367
  const optionsDirective = this.#vNode.directiveManager?.optionsDirective('component');
@@ -7375,63 +7377,24 @@ class VComponentDirective {
7375
7377
  properties = result;
7376
7378
  }
7377
7379
  }
7378
- // Store component ID
7379
- this.#componentId = componentId;
7380
7380
  // Get component definition from the application's component registry
7381
- const vApplication = this.#vNode.vApplication;
7382
- if (!vApplication) {
7383
- console.error('VApplication not found on VNode');
7384
- return;
7385
- }
7386
- const component = vApplication.componentRegistry.get(componentId);
7381
+ const component = this.#vNode.vApplication.componentRegistry.get(this.#componentId);
7387
7382
  if (!component) {
7388
- console.error(`Component '${componentId}' not found in registry`);
7389
- return;
7390
- }
7391
- // Get template element
7392
- const finalTemplateID = component.templateID;
7393
- const templateElement = document.querySelector(`#${finalTemplateID}`);
7394
- if (!templateElement || !(templateElement instanceof HTMLTemplateElement)) {
7395
- console.error(`Template element '#${finalTemplateID}' not found`);
7396
- return;
7383
+ throw new Error(`Component '${this.#componentId}' not found in registry`);
7397
7384
  }
7398
- // Clone template content
7399
- const fragment = templateElement.content.cloneNode(true);
7400
- const childNodes = Array.from(fragment.childNodes);
7401
- // Find the first element node
7402
- let componentElement;
7403
- for (const node of childNodes) {
7404
- if (node.nodeType === Node.ELEMENT_NODE) {
7405
- componentElement = node;
7406
- break;
7407
- }
7408
- }
7409
- if (!componentElement) {
7410
- console.error(`No element found in template '#${finalTemplateID}'`);
7411
- return;
7412
- }
7413
- // Replace element with component element
7414
- const parent = element.parentNode;
7415
- if (!parent) {
7416
- console.error(`Element has no parent node. Component '${componentId}' cannot be mounted.`);
7417
- return;
7418
- }
7419
- parent.insertBefore(componentElement, element);
7420
- parent.removeChild(element);
7421
7385
  // Create component instance
7422
7386
  const instance = component.createInstance(properties);
7423
7387
  // Create and mount child application using the parent application's registries
7424
- this.#childApp = vApplication.createChildApp(instance);
7425
- this.#childApp.mount(componentElement);
7388
+ this.#childApp = this.#vNode.vApplication.createChildApp(instance);
7389
+ this.#childApp.mount(this.#vNode.node);
7426
7390
  this.#isActivated = true;
7427
7391
  }
7428
7392
  /**
7429
7393
  * Cleans up the component.
7430
7394
  */
7431
- cleanupComponent() {
7395
+ #cleanupComponent() {
7432
7396
  if (this.#childApp) {
7433
- // TODO: Implement unmount when available in VApplication
7434
- // this.#childApp.unmount();
7397
+ this.#childApp.unmount();
7435
7398
  this.#childApp = undefined;
7436
7399
  }
7437
7400
  this.#isActivated = false;
@@ -7769,6 +7732,11 @@ class VDirectiveManager {
7769
7732
  * The keys are directive names (e.g., 'options', 'options.intersection').
7770
7733
  */
7771
7734
  #optionsDirectives = {};
7735
+ /**
7736
+ * The v-component directive associated with this node, if any.
7737
+ * This may be undefined if there is no v-component directive.
7738
+ */
7739
+ #componentDirective;
7772
7740
  constructor(vNode) {
7773
7741
  // Directives can only be associated with element nodes
7774
7742
  if (vNode.nodeType !== Node.ELEMENT_NODE) {
@@ -7827,11 +7795,11 @@ class VDirectiveManager {
7827
7795
  return this.#keyDirective;
7828
7796
  }
7829
7797
  /**
7830
- * Gets a record of VBindDirectives for options specific to certain directives.
7831
- * The keys are directive names (e.g., 'options', 'options.intersection').
7798
+ * Gets the v-component directive associated with this node, if any.
7799
+ * This may be undefined if there is no v-component directive.
7832
7800
  */
7833
- get optionsDirectives() {
7834
- return this.#optionsDirectives;
7801
+ get componentDirective() {
7802
+ return this.#componentDirective;
7835
7803
  }
7836
7804
  /**
7837
7805
  * Gets the VBindDirective for options specific to the given directive name.
@@ -7922,6 +7890,10 @@ class VDirectiveManager {
7922
7890
  this.#optionsDirectives[attrName] = bindDirective;
7923
7891
  }
7924
7892
  }
7893
+ // If this is a v-component directive, store it separately
7894
+ if (directive.name === StandardDirectiveName.V_COMPONENT) {
7895
+ this.#componentDirective = directive;
7896
+ }
7925
7897
  }
7926
7898
  }
7927
7899
  // Sort directives by priority: v-for > v-if > v-else-if > v-else > v-show > others
@@ -8875,8 +8847,15 @@ class VConditionalDirective {
8875
8847
  * Clones the template element and creates a new VNode for the cloned element.
8876
8848
  */
8877
8849
  #cloneTemplate() {
8878
- const element = this.#vNode.node;
8879
- const clone = element.cloneNode(true);
8850
+ // Clone the original element
8851
+ let clone;
8852
+ if (this.vNode.directiveManager?.componentDirective) {
8853
+ clone = this.vNode.directiveManager.componentDirective.cloneNode();
8854
+ }
8855
+ else {
8856
+ const element = this.#vNode.node;
8857
+ clone = element.cloneNode(true);
8858
+ }
8880
8859
  // Create a new VNode for the cloned element
8881
8860
  const vNode = new VNode({
8882
8861
  node: clone,
@@ -9311,8 +9290,15 @@ class VForDirective {
9311
9290
  * Clone template element for each iteration and create a new VNode
9312
9291
  */
9313
9292
  #cloneTemplate(context) {
9314
- const element = this.#vNode.node;
9315
- const clone = element.cloneNode(true);
9293
+ // 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
+ }
9316
9302
  // Prepare identifiers for the item
9317
9303
  this.#itemName;
9318
9304
  this.#indexName;
@@ -11217,6 +11203,16 @@ class VApplication {
11217
11203
  this.#vNode.update();
11218
11204
  this.#logger.info('Application mounted.');
11219
11205
  }
11206
+ /**
11207
+ * Unmounts the application and cleans up resources.
11208
+ */
11209
+ unmount() {
11210
+ if (this.#vNode) {
11211
+ this.#vNode.destroy();
11212
+ this.#vNode = undefined;
11213
+ }
11214
+ this.#logger.info('Application unmounted.');
11215
+ }
11220
11216
  /**
11221
11217
  * Creates a child application instance with the same registries.
11222
11218
  * @param options The application options for the child.