@mintjamsinc/ichigojs 0.1.13 → 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.
- package/dist/ichigo.esm.js +64 -77
- package/dist/ichigo.esm.js.map +1 -1
- package/dist/ichigo.esm.min.js +1 -1
- package/dist/ichigo.esm.min.js.map +1 -1
- package/dist/ichigo.umd.js +64 -77
- package/dist/ichigo.umd.js.map +1 -1
- package/dist/ichigo.umd.min.js +1 -1
- package/dist/ichigo.umd.min.js.map +1 -1
- package/dist/types/ichigo/directives/VComponentDirective.d.ts +1 -8
- package/dist/types/ichigo/directives/VDirectiveManager.d.ts +4 -3
- package/package.json +1 -1
package/dist/ichigo.esm.js
CHANGED
@@ -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.#
|
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
|
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
|
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
|
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,60 +7377,22 @@ 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
|
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
|
-
|
7389
|
-
return;
|
7383
|
+
throw new Error(`Component '${this.#componentId}' not found in registry`);
|
7390
7384
|
}
|
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;
|
7397
|
-
}
|
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(
|
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
7397
|
this.#childApp.unmount();
|
7434
7398
|
this.#childApp = undefined;
|
@@ -7768,6 +7732,11 @@ class VDirectiveManager {
|
|
7768
7732
|
* The keys are directive names (e.g., 'options', 'options.intersection').
|
7769
7733
|
*/
|
7770
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;
|
7771
7740
|
constructor(vNode) {
|
7772
7741
|
// Directives can only be associated with element nodes
|
7773
7742
|
if (vNode.nodeType !== Node.ELEMENT_NODE) {
|
@@ -7826,11 +7795,11 @@ class VDirectiveManager {
|
|
7826
7795
|
return this.#keyDirective;
|
7827
7796
|
}
|
7828
7797
|
/**
|
7829
|
-
* Gets
|
7830
|
-
*
|
7798
|
+
* Gets the v-component directive associated with this node, if any.
|
7799
|
+
* This may be undefined if there is no v-component directive.
|
7831
7800
|
*/
|
7832
|
-
get
|
7833
|
-
return this.#
|
7801
|
+
get componentDirective() {
|
7802
|
+
return this.#componentDirective;
|
7834
7803
|
}
|
7835
7804
|
/**
|
7836
7805
|
* Gets the VBindDirective for options specific to the given directive name.
|
@@ -7921,6 +7890,10 @@ class VDirectiveManager {
|
|
7921
7890
|
this.#optionsDirectives[attrName] = bindDirective;
|
7922
7891
|
}
|
7923
7892
|
}
|
7893
|
+
// If this is a v-component directive, store it separately
|
7894
|
+
if (directive.name === StandardDirectiveName.V_COMPONENT) {
|
7895
|
+
this.#componentDirective = directive;
|
7896
|
+
}
|
7924
7897
|
}
|
7925
7898
|
}
|
7926
7899
|
// Sort directives by priority: v-for > v-if > v-else-if > v-else > v-show > others
|
@@ -8874,8 +8847,15 @@ class VConditionalDirective {
|
|
8874
8847
|
* Clones the template element and creates a new VNode for the cloned element.
|
8875
8848
|
*/
|
8876
8849
|
#cloneTemplate() {
|
8877
|
-
|
8878
|
-
|
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
|
+
}
|
8879
8859
|
// Create a new VNode for the cloned element
|
8880
8860
|
const vNode = new VNode({
|
8881
8861
|
node: clone,
|
@@ -9310,8 +9290,15 @@ class VForDirective {
|
|
9310
9290
|
* Clone template element for each iteration and create a new VNode
|
9311
9291
|
*/
|
9312
9292
|
#cloneTemplate(context) {
|
9313
|
-
|
9314
|
-
|
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
|
+
}
|
9315
9302
|
// Prepare identifiers for the item
|
9316
9303
|
this.#itemName;
|
9317
9304
|
this.#indexName;
|