mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-08-06 13:38:49 +08:00
feat: add forEach command
This commit is contained in:
parent
78e2a6e775
commit
783ce4e3ac
24
packages/core/src/commands/forEach.ts
Normal file
24
packages/core/src/commands/forEach.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands<ReturnType> {
|
||||
forEach: {
|
||||
/**
|
||||
* Loop through an array of items.
|
||||
*/
|
||||
forEach: <T>(
|
||||
items: T[],
|
||||
fn: (
|
||||
item: T,
|
||||
props: Parameters<Command>[0] & {
|
||||
index: number,
|
||||
},
|
||||
) => boolean,
|
||||
) => ReturnType,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const forEach: RawCommands['forEach'] = (items, fn) => props => {
|
||||
return items.every((item, index) => fn(item, { ...props, index }))
|
||||
}
|
@ -11,6 +11,7 @@ import * as exitCode from '../commands/exitCode'
|
||||
import * as extendMarkRange from '../commands/extendMarkRange'
|
||||
import * as first from '../commands/first'
|
||||
import * as focus from '../commands/focus'
|
||||
import * as forEach from '../commands/forEach'
|
||||
import * as insertContent from '../commands/insertContent'
|
||||
import * as insertContentAt from '../commands/insertContentAt'
|
||||
import * as joinBackward from '../commands/joinBackward'
|
||||
@ -60,6 +61,7 @@ export { exitCode }
|
||||
export { extendMarkRange }
|
||||
export { first }
|
||||
export { focus }
|
||||
export { forEach }
|
||||
export { insertContent }
|
||||
export { insertContentAt }
|
||||
export { joinBackward }
|
||||
@ -114,6 +116,7 @@ export const Commands = Extension.create({
|
||||
...extendMarkRange,
|
||||
...first,
|
||||
...focus,
|
||||
...forEach,
|
||||
...insertContent,
|
||||
...insertContentAt,
|
||||
...joinBackward,
|
||||
|
Loading…
Reference in New Issue
Block a user