onelaraveljs 1.21.13 → 1.21.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onelaraveljs",
3
- "version": "1.21.13",
3
+ "version": "1.21.15",
4
4
  "description": "OneLaravel JS Framework Core & Compiler",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -2,6 +2,11 @@ import { __defineProp, __hasOwnProp } from '../helpers/utils.js';
2
2
  import OneDOM from './OneDOM.js';
3
3
  import { TemplateDetectorService } from './services/TemplateDetectorService.js';
4
4
 
5
+ /**
6
+ * @type {OneMarkupService}
7
+ */
8
+ let oms = null;
9
+
5
10
  export class OneMarkupModel {
6
11
  constructor(fullName, openTag, closeTag, attributes = {}, nodes = []) {
7
12
  /**
@@ -20,6 +25,7 @@ export class OneMarkupModel {
20
25
  this.__definedAttributes = [];
21
26
  this.__tagName = fullName.split(':')[1];
22
27
  this.__fullName = fullName;
28
+ this.__query = null;
23
29
  this.__defineAttributes(Object.keys(attributes));
24
30
  }
25
31
  __update(fullName, openTag, closeTag, attributes = {}, nodes = []) {
@@ -165,6 +171,16 @@ export class OneMarkupModel {
165
171
  this.__nodes.push(...nodes);
166
172
  return this.__nodes;
167
173
  }
174
+ __sync() {
175
+ if(this.__query){
176
+ const result = oms.find(this.__query.pattern, this.__query.attributes, this.__query.options, this.__query.index, true);
177
+ if(result){
178
+ this.__update(result.fullName, result.openTag, result.closeTag, result.attributes, result.nodes);
179
+ return true;
180
+ }
181
+ }
182
+ return false;
183
+ }
168
184
  updateNodes(nodes = []) {
169
185
  this.__nodes = nodes;
170
186
  return this;
@@ -351,9 +367,9 @@ export class OneMarkupService {
351
367
  const elements = this.detector.find("one:" + pattern, options);
352
368
  const isTotal = total && typeof total === 'number' && total !== 0;
353
369
  const isLast = isTotal && total === -1 && isOne;
354
- const isFirst = total && total === 1 && isOne;
370
+ const isFirst = ((total === false || total === null || total === 0) && isOne) || (isTotal && total === 1 && !isOne);
355
371
  const isRight = isTotal && total < 0 && !isOne;
356
- const oneIndex = isOne && isTotal && !isLast && !isFirst ? (total >= 0 ? (elements.length - total > 0 ? total : 0) : 0) : (elements.length + total > 0 ? (elements.length + total - 1): elements.length - 1);
372
+ const oneIndex = isOne && isTotal && !isLast && !isFirst ? (total >= 0 ? (elements.length - total > 0 ? total : 0) : 0) : (elements.length + total > 0 ? (elements.length + total - 1): elements.length - 1); // total is index
357
373
 
358
374
  if (elements.length === 0) {
359
375
  if (isLast || isFirst) {
@@ -452,11 +468,21 @@ export class OneMarkupService {
452
468
  return new OneMarkupCollection(result);
453
469
  }
454
470
  findOne(pattern = '*', attributes = {}, options = {}, index = 0) {
455
- return this.find(pattern, attributes, options, index, true);
471
+ const result = this.find(pattern, attributes, options, index, true);
472
+ if(result === null){
473
+ return null;
474
+ }
475
+ result.__query = { pattern, attributes, options, index };
476
+ return result;
456
477
  }
457
478
 
458
479
  first(pattern = '*', attributes = {}, options = {}) {
459
- return this.find(pattern, attributes, options, 1, true);
480
+ const result = this.find(pattern, attributes, options, 0, true);
481
+ if(result === null){
482
+ return null;
483
+ }
484
+ result.__query = { pattern, attributes, options, total: 1, index: 0 };
485
+ return result;
460
486
  }
461
487
  last(pattern = '*', attributes = {}, options = {}) {
462
488
  return this.find(pattern, attributes, options, -1, true);
@@ -467,4 +493,5 @@ export class OneMarkupService {
467
493
  }
468
494
 
469
495
  export const OneMarkup = new OneMarkupService();
496
+ oms = OneMarkup;
470
497
  export default OneMarkup;
@@ -101,7 +101,7 @@ export class ReactiveComponent {
101
101
  * Mount component và thiết lập state subscriptions
102
102
  */
103
103
  mounted() {
104
- if (this.isMounted || this.isDestroyed) return;
104
+ if (this.isMounted) return;
105
105
 
106
106
  // console.log(`ReactiveComponent mounted [${this.type}]:`, this.id);
107
107
 
@@ -130,11 +130,12 @@ export class ReactiveComponent {
130
130
  * Unmount component và dọn dẹp subscriptions
131
131
  */
132
132
  unmounted() {
133
- if (!this.isMounted || this.isDestroyed) return;
133
+ if (!this.isMounted) return;
134
134
 
135
135
  // console.log(`ReactiveComponent unmounted [${this.type}]:`, this.id);
136
136
 
137
137
  this.isMounted = false;
138
+ this.isScanned = false;
138
139
 
139
140
  // Unmount children cho loại watch
140
141
  if (this.type === 'watch') {
@@ -142,13 +143,14 @@ export class ReactiveComponent {
142
143
  }
143
144
 
144
145
  this._unsubscribeAll();
146
+ this.markup = null;
145
147
  }
146
148
 
147
149
  /**
148
150
  * Cập nhật component khi state thay đổi
149
151
  */
150
152
  update() {
151
- if (this._isUpdating || !this.isMounted || this.isDestroyed) return;
153
+ if (this._isUpdating || !this.isMounted) return;
152
154
 
153
155
  this._isUpdating = true;
154
156
 
@@ -318,6 +320,7 @@ export class ReactiveComponent {
318
320
  this.closeTag = this.markup.closeTag;
319
321
  this.refElements = this.markup.nodes.slice();
320
322
  } else {
323
+ this.markup.__sync();
321
324
  // Quét lại markup hiện tại - validate trước
322
325
  if (!this.markup.openTag?.isConnected || !this.markup.closeTag?.isConnected) {
323
326
  console.warn(`ReactiveComponent [${this.type}][${this.id}]: Cannot re-scan, markup disconnected`);