cotomy 0.4.1 → 0.4.2

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/README.md CHANGED
@@ -76,8 +76,8 @@ The View layer provides thin wrappers around DOM elements and window events.
76
76
  - `lastChild(selector = "*", type?)`
77
77
  - `closest(selector, type?)`
78
78
  - `find(selector, type?)` / `first(selector = "*", type?)` / `last(selector = "*", type?)` / `contains(selector)`
79
- - `append(child): this` / `prepend(child): this` / `appendAll(children): this`
80
- - `insertBefore(sibling): this` / `insertAfter(sibling): this`
79
+ - `append(child): this` / `prepend(child): this` / `appendAll(children): this` — accepts `CotomyElement`, HTML string, or `{ html, css? }`
80
+ - `insertBefore(sibling): this` / `insertAfter(sibling): this` — accepts `CotomyElement`, HTML string, or `{ html, css? }`
81
81
  - `appendTo(target): this` / `prependTo(target): this`
82
82
  - `comesBefore(target): boolean` / `comesAfter(target): boolean` — Checks DOM order (returns `false` for the same element or disconnected nodes)
83
83
  - `clone(type?): CotomyElement` - Returns a deep-cloned element, optionally typed, and reassigns a new `data-cotomy-instance` while preserving the `data-cotomy-scopeid` for scoped CSS sharing (strips `data-cotomy-moving`). Cloning an invalidated element (`data-cotomy-invalidated`) throws.
@@ -160,7 +160,7 @@ npm test -- --run tests/view.spec.ts -t "compares document order with comesBefor
160
160
  - `initialize(): this`
161
161
  - DOM helpers
162
162
  - `body: CotomyElement`
163
- - `append(element: CotomyElement): this`
163
+ - `append(element: CotomyElement | string | { html: string, css?: string }): this`
164
164
  - `scrollTo(target, options?: CotomyScrollOptions | Partial<CotomyScrollOptions>): this` — Scrolls to reveal a target (`selector | CotomyElement | HTMLElement`)
165
165
  - `moveNext(focused: CotomyElement, shift = false)` — Move focus to next/previous focusable
166
166
  - Window events
@@ -1616,18 +1616,23 @@ class CotomyElement {
1616
1616
  target.trigger("cotomy:transitend");
1617
1617
  }
1618
1618
  }
1619
+ static toElement(target) {
1620
+ return target instanceof CotomyElement ? target : new CotomyElement(target);
1621
+ }
1619
1622
  prepend(prepend) {
1620
- CotomyElement.runWithMoveEvents(prepend, () => {
1621
- this.element.prepend(prepend.element);
1623
+ const e = CotomyElement.toElement(prepend);
1624
+ CotomyElement.runWithMoveEvents(e, () => {
1625
+ this.element.prepend(e.element);
1622
1626
  });
1623
- prepend.ensureScopedCss();
1627
+ e.ensureScopedCss();
1624
1628
  return this;
1625
1629
  }
1626
1630
  append(target) {
1627
- CotomyElement.runWithMoveEvents(target, () => {
1628
- this.element.append(target.element);
1631
+ const e = CotomyElement.toElement(target);
1632
+ CotomyElement.runWithMoveEvents(e, () => {
1633
+ this.element.append(e.element);
1629
1634
  });
1630
- target.ensureScopedCss();
1635
+ e.ensureScopedCss();
1631
1636
  return this;
1632
1637
  }
1633
1638
  appendAll(targets) {
@@ -1635,17 +1640,19 @@ class CotomyElement {
1635
1640
  return this;
1636
1641
  }
1637
1642
  insertBefore(append) {
1638
- CotomyElement.runWithMoveEvents(append, () => {
1639
- this.element.before(append.element);
1643
+ const e = CotomyElement.toElement(append);
1644
+ CotomyElement.runWithMoveEvents(e, () => {
1645
+ this.element.before(e.element);
1640
1646
  });
1641
- append.ensureScopedCss();
1647
+ e.ensureScopedCss();
1642
1648
  return this;
1643
1649
  }
1644
1650
  insertAfter(append) {
1645
- CotomyElement.runWithMoveEvents(append, () => {
1646
- this.element.after(append.element);
1651
+ const e = CotomyElement.toElement(append);
1652
+ CotomyElement.runWithMoveEvents(e, () => {
1653
+ this.element.after(e.element);
1647
1654
  });
1648
- append.ensureScopedCss();
1655
+ e.ensureScopedCss();
1649
1656
  return this;
1650
1657
  }
1651
1658
  appendTo(target) {