Class 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 Detail

      • YXmlFragment

        public YXmlFragment()
    • Method Detail

      • 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.
      • 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
      • createTreeWalker

        public YXmlTreeWalker createTreeWalker​(java.util.function.Function<AbstractType,​java.lang.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​(java.lang.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 java.util.List<AbstractType> querySelectorAll​(java.lang.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,
                                 java.util.Set<java.lang.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 java.lang.String toString()
        Get the string representation of all the children of this YXmlFragment.
        Overrides:
        toString in class java.lang.Object
        Returns:
        The string representation of all children.
      • toJSON

        public java.lang.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,
                           java.util.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​(java.lang.Object ref,
                                java.util.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 java.lang.Object[] toArray()
        Transforms this YArray to a Object Array.
        Returns:
        Array of YXmlElement, YXmlText, or YXmlHook.
      • toList

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

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

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

        public java.lang.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 java.util.List<java.lang.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<java.lang.Object,​java.lang.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