Class YXmlFragment<T>

java.lang.Object
io.keikai.doc.collab.types.AbstractType<YXmlEvent>
io.keikai.doc.collab.types.YXmlFragment<T>
Direct Known Subclasses:
YXmlElement

public class YXmlFragment<T> extends AbstractType<YXmlEvent>
Represents a list of YXmlElement.and YXmlText types. A YxmlFragment is similar to a YXmlElement, but it does not have a nodeName, and it does not have attributes. Though it can be bound to a DOM element - in this case the attributes and the nodeName are not shared.
  • Constructor Details

    • YXmlFragment

      public YXmlFragment()
  • Method Details

    • getFirstChild

      public AbstractType getFirstChild()
      Returns:
      YXmlElement or YXmlText|null
    • integrate

      public void integrate(Doc y, Item item)
      Integrate this type into the Yjs instance. * Save this struct in the os * This type is sent to other clients * Observer functions are fired
      Overrides:
      integrate in class AbstractType<YXmlEvent>
      Parameters:
      y - The Yjs instance.
      item - The item to integrate.
    • copy

      public YXmlFragment copy()
      Overrides:
      copy in class AbstractType<YXmlEvent>
    • clone

      public YXmlFragment clone()
      Makes a copy of this data type that can be included somewhere else. Note that the content is only readable _after_ it has been included somewhere in the Ydoc.
      Overrides:
      clone in class AbstractType<YXmlEvent>
      Returns:
      YXmlFragment
    • length

      public int length()
      Overrides:
      length in class AbstractType<YXmlEvent>
    • createTreeWalker

      public YXmlTreeWalker createTreeWalker(Function<AbstractType,Boolean> filter)
      Create a subtree of childNodes.
      Parameters:
      filter - Function that is called on each child element and returns a Boolean indicating whether the child is to be included in the subtree.
      Returns:
      YXmlTreeWalker A subtree and a position within it.
    • querySelector

      public AbstractType querySelector(String query)
      Returns the first YXmlElement that matches the query. Similar to DOM's querySelector.
      Parameters:
      query - The query on the children.
      Returns:
      YXmlElement|YXmlText|YXmlHook|null The first element that matches the query or null.
    • querySelectorAll

      public List<AbstractType> querySelectorAll(String query)
      Returns all YXmlElements that match the query. Similar to Dom's querySelectorAll.
      Parameters:
      query - The query on the children.
      Returns:
      List of YXmlElement|YXmlText|YXmlHook|null. The elements that match this query.
    • callObserver

      public void callObserver(Transaction transaction, Set<String> parentSubs)
      Creates YXmlEvent and calls observers.
      Overrides:
      callObserver in class AbstractType<YXmlEvent>
      Parameters:
      transaction - The transaction that occurred.
      parentSubs - Keys changed on this type. `null` if the list was modified.
    • toString

      public String toString()
      Get the string representation of all the children of this YXmlFragment.
      Overrides:
      toString in class Object
      Returns:
      The string representation of all children.
    • toJSON

      public String toJSON()
      Description copied from class: AbstractType
      Converts the type to a JSON object representation.
      Overrides:
      toJSON in class AbstractType<YXmlEvent>
      Returns:
      JSON representation of the fragment.
    • insert

      public void insert(int index, List<T> content)
      Inserts new content at an index.
      Parameters:
      index - The index to insert content at.
      content - The array of content.
    • insertAfter

      public void insertAfter(Object ref, List<T> content)
      Inserts new content after a reference element.
      Parameters:
      ref - The index to insert content at.
      content - The array of content.
    • delete

      public void delete(int index)
      Deletes elements starting from an index.
      Parameters:
      index - Index at which to start deleting elements.
    • delete

      public void delete(int index, int length)
      Deletes elements starting from an index.
      Parameters:
      index - Index at which to start deleting elements.
      length - The number of elements to remove. Defaults to 1.
    • toArray

      public Object[] toArray()
      Transforms this YArray to a Object Array.
      Returns:
      Array of YXmlElement, YXmlText, or YXmlHook.
    • toList

      public List<Object> toList()
      Transforms this YArray to a Object List.
      Returns:
      Array of YXmlElement, YXmlText, or YXmlHook.
    • push

      public void push(List<T> content)
      Appends content to this YArray.
      Parameters:
      content - Array of content to append.
    • unshift

      public void unshift(List<T> content)
      Prepends content to this YArray.
      Parameters:
      content - Array of content to prepend.
    • get

      public Object get(int index)
      Returns the i-th element from a YArray.
      Parameters:
      index - The index of the element to return from the YArray.
      Returns:
      YXmlElement or YXmlText.
    • slice

      public List<Object> slice(int start, int end)
      Returns a portion of this YXmlFragment into a JavaScript Array selected from start to end (end not included).
      Parameters:
      start - Starting index.
      end - Ending index (not included).
      Returns:
      Array of YXmlElement or YXmlText.
    • forEach

      public void forEach(TriConsumer<Object,Integer,AbstractType> f)
      Executes a provided function once on every child element.
      Parameters:
      f - A function to execute on every element of this YArray.
    • write

      public void write(UpdateEncoder encoder)
      Transform the properties of this type to binary and write it to a BinaryEncoder. This is called when this Item is sent to a remote peer.
      Overrides:
      write in class AbstractType<YXmlEvent>
      Parameters:
      encoder - The encoder to write data to.
    • readYXmlFragment

      public static YXmlFragment readYXmlFragment(UpdateDecoder decoder)
      Parameters:
      decoder - The decoder to read data from.
      Returns:
      YXmlFragment