Package io.keikai.doc.collab.types
Class YText
- java.lang.Object
-
- io.keikai.doc.collab.types.AbstractType<YTextEvent>
-
- io.keikai.doc.collab.types.YText
-
- Direct Known Subclasses:
YXmlText
public class YText extends AbstractType<YTextEvent>
Type that represents text with formatting information. This type replaces y-richtext as this implementation is able to handle block formats (format information on a paragraph), embeds (complex elements like pictures and videos), and text formats (**bold**, *italic*).
-
-
Field Summary
-
Fields inherited from class io.keikai.doc.collab.types.AbstractType
_doc, _length, _map, _searchMarker
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapplyDelta(java.util.List<java.util.Map<java.lang.String,java.lang.Object>> deltasMap)voidapplyDelta(java.util.List<java.util.Map<java.lang.String,java.lang.Object>> deltasMap, boolean sanitize)voidcallObserver(Transaction transaction, java.util.Set<java.lang.String> parentSubs)Creates YTextEvent and calls observers.static voidcleanupYTextAfterTransaction(Transaction transaction)Cleans up YText formatting after a transaction.static intcleanupYTextFormatting(YText type)Cleans up unnecessary formatting attributes in the YText type.YTextclone()Makes a copy of this data type that can be included somewhere else.YTextcopy()voiddelete(int index)voiddelete(int index, int length)static booleanequalAttrs(java.lang.Object a, java.lang.Object b)Compare two attributes for equality.static ItemTextListPositionfindNextPosition(Transaction transaction, ItemTextListPosition pos, int count)voidformat(int index, int length, java.util.Map<java.lang.String,java.lang.Object> attributes)java.lang.ObjectgetAttribute(java.lang.String attributeName)java.util.Map<java.lang.String,java.lang.Object>getAttributes()java.util.List<ArraySearchMarker>getSearchMarker()voidinsert(int index, java.lang.String text)voidinsert(int index, java.lang.String text, java.util.Map<java.lang.String,java.lang.Object> attributes)voidinsertEmbed(int index, java.lang.Object embed)voidinsertEmbed(int index, java.lang.Object embed, java.util.Map<java.lang.String,java.lang.Object> attributes)static voidinsertNegatedAttributes(Transaction transaction, AbstractType parent, ItemTextListPosition currPos, java.util.Map<java.lang.String,java.lang.Object> negatedAttributes)voidintegrate(Doc y, Item item)Integrate this type into the Yjs instance.booleanisHasFormatting()intlength()Number of characters of this text type.static YTextreadYText(UpdateDecoder decoder)Reads and returns a new YText instance from the decoder.voidremoveAttribute(java.lang.String attributeName)voidsetAttribute(java.lang.String attributeName, java.lang.Object attributeValue)voidsetHasFormatting(boolean hasFormatting)voidsetSearchMarker(java.util.List<ArraySearchMarker> searchMarker)java.util.List<Delta>toDeltaList()java.util.List<Delta>toDeltaList(Snapshot snapshot, Snapshot prevSnapshot, java.util.function.BiFunction<java.lang.String,ID,java.lang.Object> computeYChange)java.util.List<java.util.Map<java.lang.String,java.lang.Object>>toDeltaMap()java.util.List<java.util.Map<java.lang.String,java.lang.Object>>toDeltaMap(Snapshot snapshot, Snapshot prevSnapshot, java.util.function.BiFunction<java.lang.String,ID,java.lang.Object> computeYChange)java.lang.StringtoJSON()Converts the type to a JSON object representation.java.lang.StringtoString()voidwrite(UpdateEncoder encoder)Writes this type's state to the encoder.-
Methods inherited from class io.keikai.doc.collab.types.AbstractType
callTypeObservers, createMapIterator, getDeepEventHandler, getDoc, getFirst, getItem, getMap, getParent, getStart, getTypeChildren, isParentOf, observe, observe, observeDeep, setLength, setMap, setStart, typeListCreateIterator, typeListDelete, typeListForEach, typeListForEachSnapshot, typeListGet, typeListInsertGenerics, typeListInsertGenericsAfter, typeListMap, typeListPushGenerics, typeListSlice, typeListToArray, typeListToArraySnapshot, typeMapDelete, typeMapGet, typeMapGetAll, typeMapGetAllSnapshot, typeMapGetSnapshot, typeMapHas, typeMapSet, unobserve, unobserveDeep
-
-
-
-
Method Detail
-
getSearchMarker
public java.util.List<ArraySearchMarker> getSearchMarker()
- Overrides:
getSearchMarkerin classAbstractType<YTextEvent>
-
setSearchMarker
public void setSearchMarker(java.util.List<ArraySearchMarker> searchMarker)
-
isHasFormatting
public boolean isHasFormatting()
-
setHasFormatting
public void setHasFormatting(boolean hasFormatting)
-
length
public int length()
Number of characters of this text type.- Overrides:
lengthin classAbstractType<YTextEvent>
-
integrate
public void integrate(Doc y, Item item)
Description copied from class:AbstractTypeIntegrate this type into the Yjs instance. Save this struct in the os This type is sent to other client Observer functions are fired- Overrides:
integratein classAbstractType<YTextEvent>- Parameters:
y- The Yjs instanceitem- The item to integrate
-
copy
public YText copy()
- Overrides:
copyin classAbstractType<YTextEvent>
-
clone
public YText clone()
Description copied from class:AbstractTypeMakes 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:
clonein classAbstractType<YTextEvent>- Returns:
- A copy of this data type
-
callObserver
public void callObserver(Transaction transaction, java.util.Set<java.lang.String> parentSubs)
Creates YTextEvent and calls observers.- Overrides:
callObserverin classAbstractType<YTextEvent>- Parameters:
transaction- The current transactionparentSubs- Keys changed on this type. `null` if list was modified.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
toJSON
public java.lang.String toJSON()
Description copied from class:AbstractTypeConverts the type to a JSON object representation.- Overrides:
toJSONin classAbstractType<YTextEvent>- Returns:
- The JSON object representation
-
applyDelta
public void applyDelta(java.util.List<java.util.Map<java.lang.String,java.lang.Object>> deltasMap)
-
applyDelta
public void applyDelta(java.util.List<java.util.Map<java.lang.String,java.lang.Object>> deltasMap, boolean sanitize)
-
toDeltaMap
public java.util.List<java.util.Map<java.lang.String,java.lang.Object>> toDeltaMap()
-
toDeltaMap
public java.util.List<java.util.Map<java.lang.String,java.lang.Object>> toDeltaMap(Snapshot snapshot, Snapshot prevSnapshot, java.util.function.BiFunction<java.lang.String,ID,java.lang.Object> computeYChange)
-
toDeltaList
public java.util.List<Delta> toDeltaList()
-
toDeltaList
public java.util.List<Delta> toDeltaList(Snapshot snapshot, Snapshot prevSnapshot, java.util.function.BiFunction<java.lang.String,ID,java.lang.Object> computeYChange)
-
insert
public void insert(int index, java.lang.String text)
-
insert
public void insert(int index, java.lang.String text, java.util.Map<java.lang.String,java.lang.Object> attributes)
-
insertEmbed
public void insertEmbed(int index, java.lang.Object embed)
-
insertEmbed
public void insertEmbed(int index, java.lang.Object embed, java.util.Map<java.lang.String,java.lang.Object> attributes)
-
delete
public void delete(int index)
-
delete
public void delete(int index, int length)
-
format
public void format(int index, int length, java.util.Map<java.lang.String,java.lang.Object> attributes)
-
removeAttribute
public void removeAttribute(java.lang.String attributeName)
-
setAttribute
public void setAttribute(java.lang.String attributeName, java.lang.Object attributeValue)
-
getAttribute
public java.lang.Object getAttribute(java.lang.String attributeName)
-
getAttributes
public java.util.Map<java.lang.String,java.lang.Object> getAttributes()
-
write
public void write(UpdateEncoder encoder)
Description copied from class:AbstractTypeWrites this type's state to the encoder.- Overrides:
writein classAbstractType<YTextEvent>- Parameters:
encoder- The encoder to write to
-
equalAttrs
public static boolean equalAttrs(java.lang.Object a, java.lang.Object b)Compare two attributes for equality.- Parameters:
a- The first attribute.b- The second attribute.- Returns:
- True if the attributes are equal, false otherwise.
-
findNextPosition
public static ItemTextListPosition findNextPosition(Transaction transaction, ItemTextListPosition pos, int count)
- Parameters:
transaction- The transaction in which this operation is happening.pos- The current position in the text list.count- The number of steps to move forward.- Returns:
- The updated position.
-
insertNegatedAttributes
public static void insertNegatedAttributes(Transaction transaction, AbstractType parent, ItemTextListPosition currPos, java.util.Map<java.lang.String,java.lang.Object> negatedAttributes)
- Parameters:
transaction- The current transaction.parent- The parent type.currPos- The current position in the text list.negatedAttributes- The attributes to be negated.
-
cleanupYTextFormatting
public static int cleanupYTextFormatting(YText type)
Cleans up unnecessary formatting attributes in the YText type.- Parameters:
type- The YText type to clean up.- Returns:
- The number of formatting attributes cleaned up.
-
cleanupYTextAfterTransaction
public static void cleanupYTextAfterTransaction(Transaction transaction)
Cleans up YText formatting after a transaction.- Parameters:
transaction- The current transaction.
-
readYText
public static YText readYText(UpdateDecoder decoder)
Reads and returns a new YText instance from the decoder.- Parameters:
decoder- The decoder to read from.- Returns:
- A new YText instance.
-
-