jj 2.7.2 → 2.8.0

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/lib/bundle.cjs CHANGED
@@ -354,9 +354,9 @@ var JJN = class _JJN extends JJET {
354
354
  * This is useful for filtering the array that is passed to `append()`, `prepend()` or `setChildren()`
355
355
  *
356
356
  * @param x an unknown value
357
- * @returns true if `x` is a string, Node (or its descendents), JJN (or its descendents)
357
+ * @returns true if `x` is a string, Node (or its descendent), JJN (or its descendent)
358
358
  */
359
- static isWrapable(x) {
359
+ static isWrappable(x) {
360
360
  return isStr(x) || isA(x, Node) || isA(x, _JJN);
361
361
  }
362
362
  /**
@@ -365,6 +365,7 @@ var JJN = class _JJN extends JJET {
365
365
  * @remarks
366
366
  * This function acts as a factory, inspecting the input type and returning the appropriate
367
367
  * subclass of `JJN` (e.g., `JJHE` for `HTMLElement`, `JJT` for `Text`).
368
+ * JJN.ts overrides this method to a richer version that handles all subclasses of JJN.
368
369
  *
369
370
  * @example
370
371
  * ```ts
@@ -377,7 +378,15 @@ var JJN = class _JJN extends JJET {
377
378
  * @throws {TypeError} If the input is not a Node, string, or JJ wrapper.
378
379
  */
379
380
  static wrap(raw) {
380
- throw new ReferenceError(`The mixin is supposed to override this method.`);
381
+ if (isObj(raw)) {
382
+ if (isA(raw, _JJN)) {
383
+ return raw;
384
+ }
385
+ if (isA(raw, Node)) {
386
+ return new _JJN(raw);
387
+ }
388
+ }
389
+ throw typeErr("raw", "a Node", raw);
381
390
  }
382
391
  /**
383
392
  * Extracts the underlying native DOM node from a wrapper.
@@ -480,9 +489,9 @@ var JJN = class _JJN extends JJET {
480
489
  * @returns This instance for chaining.
481
490
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Document/createTextNode | document.createTextNode}
482
491
  */
483
- addText(text) {
484
- if (text) {
485
- this.ref.appendChild(document.createTextNode(text));
492
+ addText(...textArr) {
493
+ if (textArr) {
494
+ this.ref.appendChild(document.createTextNode(textArr.join("")));
486
495
  }
487
496
  return this;
488
497
  }
@@ -547,7 +556,7 @@ var JJNx = class extends JJN {
547
556
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/append | Element.append}
548
557
  */
549
558
  addChild(...children) {
550
- const nodes = JJN.unwrapAll(children.filter(JJN.isWrapable));
559
+ const nodes = JJN.unwrapAll(children.filter(JJN.isWrappable));
551
560
  this.ref.append(...nodes);
552
561
  return this;
553
562
  }
@@ -567,7 +576,7 @@ var JJNx = class extends JJN {
567
576
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/prepend | Element.prepend}
568
577
  */
569
578
  preChild(...children) {
570
- const nodes = JJN.unwrapAll(children.filter(JJN.isWrapable));
579
+ const nodes = JJN.unwrapAll(children.filter(JJN.isWrappable));
571
580
  this.ref.prepend(...nodes);
572
581
  return this;
573
582
  }
@@ -623,7 +632,7 @@ var JJNx = class extends JJN {
623
632
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Element/replaceChildren | Element.replaceChildren}
624
633
  */
625
634
  setChildren(...children) {
626
- const nodes = JJN.unwrapAll(children.filter(JJN.isWrapable));
635
+ const nodes = JJN.unwrapAll(children.filter(JJN.isWrappable));
627
636
  this.ref.replaceChildren(...nodes);
628
637
  return this;
629
638
  }
@@ -1385,7 +1394,7 @@ var JJHE = class _JJHE extends JJEx {
1385
1394
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText | HTMLElement.innerText}
1386
1395
  */
1387
1396
  setText(text) {
1388
- this.ref.innerText = text ?? "";
1397
+ this.ref.innerText = text;
1389
1398
  return this;
1390
1399
  }
1391
1400
  };
@@ -1457,7 +1466,7 @@ var JJT = class _JJT extends JJN {
1457
1466
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
1458
1467
  */
1459
1468
  setText(text) {
1460
- this.ref.textContent = text ?? null;
1469
+ this.ref.textContent = text;
1461
1470
  return this;
1462
1471
  }
1463
1472
  /**
@@ -1470,14 +1479,12 @@ var JJT = class _JJT extends JJN {
1470
1479
  * console.log(text.getText()) // 'hello world'
1471
1480
  * ```
1472
1481
  *
1473
- * @param text - The string to add to the existing contents. If null or undefined, nothing is added.
1482
+ * @param textArr - The string to add to the existing contents. If null or undefined, nothing is added.
1474
1483
  * @returns This instance for chaining.
1475
1484
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
1476
1485
  */
1477
- addText(text) {
1478
- if (text != null) {
1479
- this.ref.textContent += text;
1480
- }
1486
+ addText(...textArr) {
1487
+ this.setText(this.getText() + textArr.join(""));
1481
1488
  return this;
1482
1489
  }
1483
1490
  /**
@@ -1636,7 +1643,7 @@ var JJSE = class _JJSE extends JJEx {
1636
1643
  * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent | Node.textContent}
1637
1644
  */
1638
1645
  setText(text) {
1639
- this.ref.textContent = text ?? "";
1646
+ this.ref.textContent = text;
1640
1647
  return this;
1641
1648
  }
1642
1649
  /**