2023-10-26 04:57:00 -04:00
|
|
|
import {
|
2024-08-12 05:50:54 -04:00
|
|
|
AnyOperation,
|
|
|
|
Change,
|
2023-10-26 04:57:00 -04:00
|
|
|
CommentOperation,
|
|
|
|
DeleteOperation,
|
2024-08-12 05:50:54 -04:00
|
|
|
EditOperation,
|
2023-10-26 04:57:00 -04:00
|
|
|
InsertOperation,
|
|
|
|
Operation,
|
|
|
|
} from '../../../types/change'
|
|
|
|
|
|
|
|
export const isInsertOperation = (op: Operation): op is InsertOperation =>
|
|
|
|
'i' in op
|
|
|
|
export const isCommentOperation = (op: Operation): op is CommentOperation =>
|
2024-02-08 05:10:46 -05:00
|
|
|
'c' in op
|
2023-10-26 04:57:00 -04:00
|
|
|
export const isDeleteOperation = (op: Operation): op is DeleteOperation =>
|
|
|
|
'd' in op
|
2024-08-12 05:50:54 -04:00
|
|
|
|
|
|
|
export const isInsertChange = (
|
|
|
|
change: Change<EditOperation>
|
|
|
|
): change is Change<InsertOperation> => isInsertOperation(change.op)
|
|
|
|
|
|
|
|
export const isCommentChange = (
|
|
|
|
change: Change<CommentOperation>
|
|
|
|
): change is Change<CommentOperation> => isCommentOperation(change.op)
|
|
|
|
|
|
|
|
export const isDeleteChange = (
|
|
|
|
change: Change<EditOperation>
|
|
|
|
): change is Change<DeleteOperation> => isDeleteOperation(change.op)
|
|
|
|
|
|
|
|
export const visibleTextLength = (op: AnyOperation) => {
|
|
|
|
if (isCommentOperation(op)) {
|
|
|
|
return op.c.length
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isInsertOperation(op)) {
|
|
|
|
return op.i.length
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|