-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e04e09
commit 8ebf233
Showing
6 changed files
with
81 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,5 +66,6 @@ | |
"vite-plugin-qrcode": "^0.2.3", | ||
"vite-tsconfig-paths": "^4.3.2", | ||
"vitest": "^1.5.2" | ||
} | ||
}, | ||
"packageManager": "[email protected]+sha256.0624e30eff866cdeb363b15061bdb7fd9425b17bc1bb42c22f5f4efdea21f6b3" | ||
} |
2 changes: 1 addition & 1 deletion
2
code/client/src/domain/editor/slate/handlers/history/historyHandlers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
code/client/tests/editor/slate/handlers/history/getOperations.tests.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { withHistory } from 'slate-history'; | ||
import { | ||
BaseOperation, | ||
createEditor, | ||
InsertNodeOperation, | ||
InsertTextOperation, | ||
MergeNodeOperation, | ||
Node, | ||
Path, | ||
RemoveNodeOperation, | ||
RemoveTextOperation, | ||
SetNodeOperation, | ||
SplitNodeOperation, | ||
} from 'slate'; | ||
import { Batch } from '@/domain/editor/slate/handlers/history/utils'; | ||
import { descendant } from '@/domain/editor/slate/utils/slate'; | ||
|
||
export const mockEditor = () => { | ||
const editor = withHistory(createEditor()); | ||
editor.children = [descendant('paragraph', '')]; | ||
return editor; | ||
}; | ||
|
||
export const applyBatch = (editor: any, batch: Batch) => { | ||
for (const operation of batch.operations) { | ||
editor.apply(operation); | ||
} | ||
}; | ||
|
||
export const toBatch = (...operations: BaseOperation[]): Batch => { | ||
return { | ||
operations: operations, | ||
selectionBefore: null, | ||
}; | ||
}; | ||
|
||
export const insertText = (text: string, path: Path, offset: number): InsertTextOperation => { | ||
return { type: 'insert_text', path, offset, text }; | ||
}; | ||
|
||
export const deleteText = (text: string, path: Path, offset: number): RemoveTextOperation => ({ | ||
type: 'remove_text', | ||
path, | ||
offset, | ||
text, | ||
}); | ||
|
||
export const insertNode = (node: Node, path: Path): InsertNodeOperation => ({ type: 'insert_node', path, node }); | ||
|
||
export const removeNode = (node: Node, path: Path): RemoveNodeOperation => ({ type: 'remove_node', node, path }); | ||
|
||
export const splitNode = (properties: Partial<Node>, path: Path, position: number): SplitNodeOperation => ({ | ||
type: 'split_node', | ||
path, | ||
properties, | ||
position, | ||
}); | ||
|
||
export const mergeNode = (properties: Partial<Node>, path: Path, position: number): MergeNodeOperation => ({ | ||
type: 'merge_node', | ||
path, | ||
properties, | ||
position, | ||
}); | ||
|
||
export const setNode = (properties: Partial<Node>, newProperties: Partial<Node>, path: Path): SetNodeOperation => ({ | ||
type: 'set_node', | ||
path, | ||
properties, | ||
newProperties, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,5 +46,6 @@ | |
"tsconfig-paths": "^4.2.0", | ||
"tsx": "^4.7.3", | ||
"typescript": "^5.4.5" | ||
} | ||
}, | ||
"packageManager": "[email protected]+sha256.0624e30eff866cdeb363b15061bdb7fd9425b17bc1bb42c22f5f4efdea21f6b3" | ||
} |