bigskysoftware / idiomorph

A DOM-merging algorithm
BSD 2-Clause "Simplified" License
631 stars 31 forks source link

Type definition for idiomoph #16

Open atulbhatt-system32 opened 8 months ago

atulbhatt-system32 commented 8 months ago

Typescript support for idiomorph

jollytoad commented 7 months ago

I've used this based on a flick through the code...

declare interface Idiomorph {
  morph: (oldNode: Element | Document, newContent?: string | Element | Iterable<Element> | null, options?: {
    morphStyle?: "innerHTML" | "outerHTML";
    ignoreActive?: boolean;
    ignoreActiveValue?: boolean;
    head?: {
      style?: "merge" | "append" | "morph" | "none";
    };
    callbacks?: {
      beforeNodeAdded: (node: ChildNode) => void | boolean;
      afterNodeAdded: (node: ChildNode) => void;
      beforeNodeMorphed: (oldNode: Element, newNode: Element) => void | boolean;
      afterNodeMorphed: (oldNode: Element, newNode: Element) => void;
      beforeNodeRemoved: (node: ChildNode) => void | boolean;
      afterNodeRemoved: (node: ChildNode) => void;
    };
  }) => undefined | Iterable<ChildNode>;
}

declare let Idiomorph: Idiomorph;
1cg commented 6 months ago

Happy to accept a PR for this

delaneyj commented 3 months ago

I've ported idiomorph to TS, might be useful for the typedefs https://github.com/delaneyj/datastar/blob/main/library/src/lib/external/idiomorph.ts