mirror of
https://github.com/cudr/slate-collaborative.git
synced 2026-03-02 03:40:18 +00:00
feat: update to slate 0.58 && fix site build
This commit is contained in:
@@ -3,7 +3,7 @@ import { Operation } from 'slate'
|
||||
import node from './node'
|
||||
import text from './text'
|
||||
|
||||
import { SyncDoc } from '../model'
|
||||
import { SyncValue } from '../model'
|
||||
import { toJS } from '../utils'
|
||||
|
||||
const setSelection = (doc: any) => doc
|
||||
@@ -14,7 +14,7 @@ const opType = {
|
||||
set_selection: setSelection
|
||||
}
|
||||
|
||||
const applyOperation = (doc: SyncDoc, op: Operation): SyncDoc => {
|
||||
const applyOperation = (doc: SyncValue, op: Operation): SyncValue => {
|
||||
try {
|
||||
const applyOp = opType[op.type]
|
||||
|
||||
@@ -30,7 +30,7 @@ const applyOperation = (doc: SyncDoc, op: Operation): SyncDoc => {
|
||||
}
|
||||
}
|
||||
|
||||
const applySlateOps = (doc: SyncDoc, operations: Operation[]): SyncDoc => {
|
||||
const applySlateOps = (doc: SyncValue, operations: Operation[]): SyncValue => {
|
||||
return operations.reduce(applyOperation, doc)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { InsertNodeOperation } from 'slate'
|
||||
|
||||
import { SyncDoc } from '../../model'
|
||||
import { SyncValue } from '../../model'
|
||||
import { getParent, getChildren } from '../../path'
|
||||
import { toSync } from '../../utils'
|
||||
|
||||
const insertNode = (doc: SyncDoc, op: InsertNodeOperation): SyncDoc => {
|
||||
const insertNode = (doc: SyncValue, op: InsertNodeOperation): SyncValue => {
|
||||
const [parent, index] = getParent(doc, op.path)
|
||||
|
||||
if (parent.text) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { MergeNodeOperation, Node } from 'slate'
|
||||
|
||||
import { SyncDoc } from '../../model'
|
||||
import { SyncValue } from '../../model'
|
||||
import { getParent, getChildren } from '../../path'
|
||||
import { toJS, cloneNode } from '../../utils'
|
||||
|
||||
const mergeNode = (doc: SyncDoc, op: MergeNodeOperation): SyncDoc => {
|
||||
const mergeNode = (doc: SyncValue, op: MergeNodeOperation): SyncValue => {
|
||||
const [parent, index]: [any, number] = getParent(doc, op.path)
|
||||
|
||||
const prev = parent[index - 1] || parent.children[index - 1]
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { MoveNodeOperation } from 'slate'
|
||||
|
||||
import { cloneNode } from '../../utils'
|
||||
import { SyncDoc } from '../../model'
|
||||
import { SyncValue } from '../../model'
|
||||
import { getParent, getChildren } from '../../path'
|
||||
|
||||
const moveNode = (doc: SyncDoc, op: MoveNodeOperation): SyncDoc => {
|
||||
const moveNode = (doc: SyncValue, op: MoveNodeOperation): SyncValue => {
|
||||
const [from, fromIndex] = getParent(doc, op.path)
|
||||
const [to, toIndex] = getParent(doc, op.newPath)
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { RemoveNodeOperation } from 'slate'
|
||||
|
||||
import { SyncDoc } from '../../model'
|
||||
import { SyncValue } from '../../model'
|
||||
import { getParent, getChildren } from '../../path'
|
||||
|
||||
export const removeNode = (doc: SyncDoc, op: RemoveNodeOperation): SyncDoc => {
|
||||
export const removeNode = (
|
||||
doc: SyncValue,
|
||||
op: RemoveNodeOperation
|
||||
): SyncValue => {
|
||||
const [parent, index] = getParent(doc, op.path)
|
||||
|
||||
if (parent.text) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { SetNodeOperation } from 'slate'
|
||||
|
||||
import { SyncDoc } from '../../model'
|
||||
import { SyncValue } from '../../model'
|
||||
import { getTarget } from '../../path'
|
||||
|
||||
const setNode = (doc: SyncDoc, op: SetNodeOperation): SyncDoc => {
|
||||
const setNode = (doc: SyncValue, op: SetNodeOperation): SyncValue => {
|
||||
const node = getTarget(doc, op.path)
|
||||
|
||||
const { newProperties } = op
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { SplitNodeOperation } from 'slate'
|
||||
|
||||
import { SyncDoc } from '../../model'
|
||||
import { SyncValue } from '../../model'
|
||||
import { getParent, getChildren } from '../../path'
|
||||
import { cloneNode } from '../../utils'
|
||||
|
||||
const splitNode = (doc: SyncDoc, op: SplitNodeOperation): SyncDoc => {
|
||||
const splitNode = (doc: SyncValue, op: SplitNodeOperation): SyncValue => {
|
||||
const [parent, index]: [any, number] = getParent(doc, op.path)
|
||||
|
||||
const target = getChildren(parent)[index]
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { InsertTextOperation, RemoveTextOperation } from 'slate'
|
||||
|
||||
import { getTarget } from '../path'
|
||||
import { SyncDoc } from '../model'
|
||||
import { SyncValue } from '../model'
|
||||
|
||||
export const insertText = (doc: SyncDoc, op: InsertTextOperation): SyncDoc => {
|
||||
export const insertText = (
|
||||
doc: SyncValue,
|
||||
op: InsertTextOperation
|
||||
): SyncValue => {
|
||||
const node = getTarget(doc, op.path)
|
||||
|
||||
node.text.insertAt(op.offset, ...op.text.split(''))
|
||||
@@ -11,7 +14,10 @@ export const insertText = (doc: SyncDoc, op: InsertTextOperation): SyncDoc => {
|
||||
return doc
|
||||
}
|
||||
|
||||
export const removeText = (doc: SyncDoc, op: RemoveTextOperation): SyncDoc => {
|
||||
export const removeText = (
|
||||
doc: SyncValue,
|
||||
op: RemoveTextOperation
|
||||
): SyncValue => {
|
||||
const node = getTarget(doc, op.path)
|
||||
|
||||
node.text.deleteAt(op.offset, op.text.length)
|
||||
|
||||
Reference in New Issue
Block a user