diff --git a/docs/concepts/07-editor.md b/docs/concepts/07-editor.md index de2de3856..9c3a3f214 100644 --- a/docs/concepts/07-editor.md +++ b/docs/concepts/07-editor.md @@ -111,7 +111,7 @@ Editor.insertNodes(editor, [element], { at: path }) Editor.splitNodes(editor, { at: point }) // Add a mark to all the text in a range. -Editor.addMarks(editor, [mark], { at: range }) +Editor.addMarks(editor, mark, { at: range }) ``` The editor-specific helpers are the ones you'll use most often when working with Slate editors, so it pays to become very familiar with them. diff --git a/docs/walkthroughs/04-applying-custom-formatting.md b/docs/walkthroughs/04-applying-custom-formatting.md index bbc67d6e8..d52065356 100644 --- a/docs/walkthroughs/04-applying-custom-formatting.md +++ b/docs/walkthroughs/04-applying-custom-formatting.md @@ -81,7 +81,7 @@ const App = () => { // When "B" is pressed, add a bold mark to the text. case 'b': { event.preventDefault() - Editor.addMarks(editor, [{ type: 'bold' }]) + Editor.addMarks(editor, { type: 'bold' }) break } } @@ -154,7 +154,7 @@ const App = () => { case 'b': { event.preventDefault() - Editor.addMarks(editor, [{ type: 'bold' }]) + Editor.addMarks(editor, { type: 'bold' }) break } } diff --git a/docs/walkthroughs/05-executing-commands.md b/docs/walkthroughs/05-executing-commands.md index 9236854b8..6d686bdd0 100644 --- a/docs/walkthroughs/05-executing-commands.md +++ b/docs/walkthroughs/05-executing-commands.md @@ -55,7 +55,7 @@ const App = () => { case 'b': { event.preventDefault() - Editor.addMarks(editor, [{ type: 'bold' }]) + Editor.addMarks(editor, { type: 'bold' }) break } } diff --git a/packages/slate/src/create-editor.ts b/packages/slate/src/create-editor.ts index 528d1c47f..7426178b1 100755 --- a/packages/slate/src/create-editor.ts +++ b/packages/slate/src/create-editor.ts @@ -89,7 +89,7 @@ export const createEditor = (): Editor => { if (Command.isCoreCommand(command)) { switch (command.type) { case 'add_mark': { - Editor.addMarks(editor, [command.mark]) + Editor.addMarks(editor, command.mark) break } diff --git a/packages/slate/src/interfaces/editor/transforms/mark.ts b/packages/slate/src/interfaces/editor/transforms/mark.ts index 88d209afb..a2ad230c1 100644 --- a/packages/slate/src/interfaces/editor/transforms/mark.ts +++ b/packages/slate/src/interfaces/editor/transforms/mark.ts @@ -7,7 +7,7 @@ export const MarkTransforms = { addMarks( editor: Editor, - marks: Mark[], + mark: Mark | Mark[], options: { at?: Location hanging?: boolean @@ -21,18 +21,19 @@ export const MarkTransforms = { } // De-dupe the marks being added to ensure the set is unique. + const marks = Array.isArray(mark) ? mark : [mark] const set: Mark[] = [] - for (const mark of marks) { - if (!Mark.exists(mark, set)) { - set.push(mark) + for (const m of marks) { + if (!Mark.exists(m, set)) { + set.push(m) } } for (const [node, path] of Editor.texts(editor, { at })) { - for (const mark of set) { - if (!Mark.exists(mark, node.marks)) { - editor.apply({ type: 'add_mark', path, mark }) + for (const m of set) { + if (!Mark.exists(m, node.marks)) { + editor.apply({ type: 'add_mark', path, mark: m }) } } } @@ -41,7 +42,7 @@ export const MarkTransforms = { removeMarks( editor: Editor, - marks: Mark[], + mark: Mark | Mark[], options: { at?: Location hanging?: boolean @@ -51,9 +52,10 @@ export const MarkTransforms = { const at = splitLocation(editor, options) if (at) { - for (const [mark, i, node, path] of Editor.marks(editor, { at })) { - if (Mark.exists(mark, marks)) { - editor.apply({ type: 'remove_mark', path, mark }) + const marks = Array.isArray(mark) ? mark : [mark] + for (const [m, i, node, path] of Editor.marks(editor, { at })) { + if (Mark.exists(m, marks)) { + editor.apply({ type: 'remove_mark', path, mark: m }) } } } @@ -62,7 +64,7 @@ export const MarkTransforms = { setMarks( editor: Editor, - marks: Mark[], + mark: Mark | Mark[], props: Partial, options: { at?: Location @@ -73,12 +75,13 @@ export const MarkTransforms = { const at = splitLocation(editor, options) if (at) { - for (const [mark, i, node, path] of Editor.marks(editor, { at })) { - if (Mark.exists(mark, marks)) { + const marks = Array.isArray(mark) ? mark : [mark] + for (const [m, i, node, path] of Editor.marks(editor, { at })) { + if (Mark.exists(m, marks)) { const newProps = {} for (const k in props) { - if (props[k] !== mark[k]) { + if (props[k] !== m[k]) { newProps[k] = props[k] } } @@ -87,7 +90,7 @@ export const MarkTransforms = { editor.apply({ type: 'set_mark', path, - properties: mark, + properties: m, newProperties: newProps, }) } diff --git a/packages/slate/test/transforms/addMarks/path/basic.js b/packages/slate/test/transforms/addMarks/path/basic.js index 7e22408c9..1149baaf0 100644 --- a/packages/slate/test/transforms/addMarks/path/basic.js +++ b/packages/slate/test/transforms/addMarks/path/basic.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.addMarks(editor, [{ key: 'a' }], { at: [0, 0] }) + Editor.addMarks(editor, { key: 'a' }, { at: [0, 0] }) } export const input = ( diff --git a/packages/slate/test/transforms/addMarks/range/basic.js b/packages/slate/test/transforms/addMarks/range/basic.js index b1174f492..23687eb36 100644 --- a/packages/slate/test/transforms/addMarks/range/basic.js +++ b/packages/slate/test/transforms/addMarks/range/basic.js @@ -4,12 +4,16 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.addMarks(editor, [{ key: 'a' }], { - at: { - anchor: { path: [0, 0], offset: 1 }, - focus: { path: [0, 0], offset: 3 }, - }, - }) + Editor.addMarks( + editor, + { key: 'a' }, + { + at: { + anchor: { path: [0, 0], offset: 1 }, + focus: { path: [0, 0], offset: 3 }, + }, + } + ) } export const input = ( diff --git a/packages/slate/test/transforms/addMarks/selection/block-across-edge-existing.js b/packages/slate/test/transforms/addMarks/selection/block-across-edge-existing.js index aba28b497..f4c5826c9 100644 --- a/packages/slate/test/transforms/addMarks/selection/block-across-edge-existing.js +++ b/packages/slate/test/transforms/addMarks/selection/block-across-edge-existing.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.addMarks(editor, [{ key: 'a' }]) + Editor.addMarks(editor, { key: 'a' }) } export const input = ( diff --git a/packages/slate/test/transforms/addMarks/selection/block-across-existing.js b/packages/slate/test/transforms/addMarks/selection/block-across-existing.js index 94c29946b..3b08badd1 100644 --- a/packages/slate/test/transforms/addMarks/selection/block-across-existing.js +++ b/packages/slate/test/transforms/addMarks/selection/block-across-existing.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.addMarks(editor, [{ key: 'a' }]) + Editor.addMarks(editor, { key: 'a' }) } export const input = ( diff --git a/packages/slate/test/transforms/addMarks/selection/block-across.js b/packages/slate/test/transforms/addMarks/selection/block-across.js index d228ac72c..b0a3d290c 100644 --- a/packages/slate/test/transforms/addMarks/selection/block-across.js +++ b/packages/slate/test/transforms/addMarks/selection/block-across.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.addMarks(editor, [{ key: 'a' }]) + Editor.addMarks(editor, { key: 'a' }) } export const input = ( diff --git a/packages/slate/test/transforms/addMarks/selection/existing.js b/packages/slate/test/transforms/addMarks/selection/existing.js index bbecfeab6..c68103f68 100644 --- a/packages/slate/test/transforms/addMarks/selection/existing.js +++ b/packages/slate/test/transforms/addMarks/selection/existing.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.addMarks(editor, [{ key: 'a' }]) + Editor.addMarks(editor, { key: 'a' }) } export const input = ( diff --git a/packages/slate/test/transforms/addMarks/selection/first-character.js b/packages/slate/test/transforms/addMarks/selection/first-character.js index febf374e9..2c76fcfaa 100644 --- a/packages/slate/test/transforms/addMarks/selection/first-character.js +++ b/packages/slate/test/transforms/addMarks/selection/first-character.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.addMarks(editor, [{ key: 'a' }]) + Editor.addMarks(editor, { key: 'a' }) } export const input = ( diff --git a/packages/slate/test/transforms/addMarks/selection/inline-across.js b/packages/slate/test/transforms/addMarks/selection/inline-across.js index ed6e5bd65..7ce3a22b5 100644 --- a/packages/slate/test/transforms/addMarks/selection/inline-across.js +++ b/packages/slate/test/transforms/addMarks/selection/inline-across.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.addMarks(editor, [{ key: 'a' }]) + Editor.addMarks(editor, { key: 'a' }) } export const input = ( diff --git a/packages/slate/test/transforms/addMarks/selection/last-character.js b/packages/slate/test/transforms/addMarks/selection/last-character.js index afc9b234e..499273a43 100644 --- a/packages/slate/test/transforms/addMarks/selection/last-character.js +++ b/packages/slate/test/transforms/addMarks/selection/last-character.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.addMarks(editor, [{ key: 'a' }]) + Editor.addMarks(editor, { key: 'a' }) } export const input = ( diff --git a/packages/slate/test/transforms/addMarks/selection/middle-character.js b/packages/slate/test/transforms/addMarks/selection/middle-character.js index a452a3665..e0c1ba2b0 100644 --- a/packages/slate/test/transforms/addMarks/selection/middle-character.js +++ b/packages/slate/test/transforms/addMarks/selection/middle-character.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.addMarks(editor, [{ key: 'a' }]) + Editor.addMarks(editor, { key: 'a' }) } export const input = ( diff --git a/packages/slate/test/transforms/addMarks/selection/word.js b/packages/slate/test/transforms/addMarks/selection/word.js index 23193f4d6..0f3dd87be 100644 --- a/packages/slate/test/transforms/addMarks/selection/word.js +++ b/packages/slate/test/transforms/addMarks/selection/word.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.addMarks(editor, [{ key: 'a' }]) + Editor.addMarks(editor, { key: 'a' }) } export const input = ( diff --git a/packages/slate/test/transforms/removeMarks/path/basic.js b/packages/slate/test/transforms/removeMarks/path/basic.js index 5221cbc61..7fcfc1f0e 100644 --- a/packages/slate/test/transforms/removeMarks/path/basic.js +++ b/packages/slate/test/transforms/removeMarks/path/basic.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.removeMarks(editor, [{ key: 'a' }], { at: [0, 0] }) + Editor.removeMarks(editor, { key: 'a' }, { at: [0, 0] }) } export const input = ( diff --git a/packages/slate/test/transforms/removeMarks/range/basic.js b/packages/slate/test/transforms/removeMarks/range/basic.js index 9696d15e5..1d6d2c81d 100644 --- a/packages/slate/test/transforms/removeMarks/range/basic.js +++ b/packages/slate/test/transforms/removeMarks/range/basic.js @@ -4,12 +4,16 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.removeMarks(editor, [{ key: 'a' }], { - at: { - anchor: { path: [0, 1], offset: 0 }, - focus: { path: [0, 1], offset: 2 }, - }, - }) + Editor.removeMarks( + editor, + { key: 'a' }, + { + at: { + anchor: { path: [0, 1], offset: 0 }, + focus: { path: [0, 1], offset: 2 }, + }, + } + ) } export const input = ( diff --git a/packages/slate/test/transforms/removeMarks/selection/across-blocks.js b/packages/slate/test/transforms/removeMarks/selection/across-blocks.js index 8c3a8ae63..72ea66699 100644 --- a/packages/slate/test/transforms/removeMarks/selection/across-blocks.js +++ b/packages/slate/test/transforms/removeMarks/selection/across-blocks.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.removeMarks(editor, [{ key: 'a' }]) + Editor.removeMarks(editor, { key: 'a' }) } export const input = ( diff --git a/packages/slate/test/transforms/removeMarks/selection/across-inlines.js b/packages/slate/test/transforms/removeMarks/selection/across-inlines.js index a9b14aca4..887bfa039 100644 --- a/packages/slate/test/transforms/removeMarks/selection/across-inlines.js +++ b/packages/slate/test/transforms/removeMarks/selection/across-inlines.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.removeMarks(editor, [{ key: 'a' }]) + Editor.removeMarks(editor, { key: 'a' }) } export const input = ( diff --git a/packages/slate/test/transforms/removeMarks/selection/collapsed-selection.js b/packages/slate/test/transforms/removeMarks/selection/collapsed-selection.js index 2c020ebfa..e598f0195 100644 --- a/packages/slate/test/transforms/removeMarks/selection/collapsed-selection.js +++ b/packages/slate/test/transforms/removeMarks/selection/collapsed-selection.js @@ -4,8 +4,8 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.addMarks(editor, [{ key: 'a' }]) - Editor.removeMarks(editor, [{ key: 'a' }]) + Editor.addMarks(editor, { key: 'a' }) + Editor.removeMarks(editor, { key: 'a' }) Editor.insertText(editor, 'a') } diff --git a/packages/slate/test/transforms/removeMarks/selection/existing-marks.js b/packages/slate/test/transforms/removeMarks/selection/existing-marks.js index 900d9562e..712ca820e 100644 --- a/packages/slate/test/transforms/removeMarks/selection/existing-marks.js +++ b/packages/slate/test/transforms/removeMarks/selection/existing-marks.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.removeMarks(editor, [{ key: 'a' }]) + Editor.removeMarks(editor, { key: 'a' }) } export const input = ( diff --git a/packages/slate/test/transforms/removeMarks/selection/first-character.js b/packages/slate/test/transforms/removeMarks/selection/first-character.js index 7ec229087..74c826c2e 100644 --- a/packages/slate/test/transforms/removeMarks/selection/first-character.js +++ b/packages/slate/test/transforms/removeMarks/selection/first-character.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.removeMarks(editor, [{ key: 'a' }]) + Editor.removeMarks(editor, { key: 'a' }) } export const input = ( diff --git a/packages/slate/test/transforms/removeMarks/selection/last-character.js b/packages/slate/test/transforms/removeMarks/selection/last-character.js index 54ab1f98f..548150152 100644 --- a/packages/slate/test/transforms/removeMarks/selection/last-character.js +++ b/packages/slate/test/transforms/removeMarks/selection/last-character.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.removeMarks(editor, [{ key: 'a' }]) + Editor.removeMarks(editor, { key: 'a' }) } export const input = ( diff --git a/packages/slate/test/transforms/removeMarks/selection/middle-character.js b/packages/slate/test/transforms/removeMarks/selection/middle-character.js index d6d213096..f773724e1 100644 --- a/packages/slate/test/transforms/removeMarks/selection/middle-character.js +++ b/packages/slate/test/transforms/removeMarks/selection/middle-character.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.removeMarks(editor, [{ key: 'a' }]) + Editor.removeMarks(editor, { key: 'a' }) } export const input = ( diff --git a/packages/slate/test/transforms/removeMarks/selection/part-of-mark-backward.js b/packages/slate/test/transforms/removeMarks/selection/part-of-mark-backward.js index 2ecbbadf0..9d1e4e161 100644 --- a/packages/slate/test/transforms/removeMarks/selection/part-of-mark-backward.js +++ b/packages/slate/test/transforms/removeMarks/selection/part-of-mark-backward.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.removeMarks(editor, [{ key: 'a' }]) + Editor.removeMarks(editor, { key: 'a' }) } export const input = ( diff --git a/packages/slate/test/transforms/removeMarks/selection/part-of-mark.js b/packages/slate/test/transforms/removeMarks/selection/part-of-mark.js index 02db52f39..c5407d1a8 100644 --- a/packages/slate/test/transforms/removeMarks/selection/part-of-mark.js +++ b/packages/slate/test/transforms/removeMarks/selection/part-of-mark.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.removeMarks(editor, [{ key: 'a' }]) + Editor.removeMarks(editor, { key: 'a' }) } export const input = ( diff --git a/packages/slate/test/transforms/removeMarks/selection/whole-word.js b/packages/slate/test/transforms/removeMarks/selection/whole-word.js index 2bab0a322..9204e60ec 100644 --- a/packages/slate/test/transforms/removeMarks/selection/whole-word.js +++ b/packages/slate/test/transforms/removeMarks/selection/whole-word.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.removeMarks(editor, [{ key: 'a' }]) + Editor.removeMarks(editor, { key: 'a' }) } export const input = ( diff --git a/packages/slate/test/transforms/setMarks/path/basic.js b/packages/slate/test/transforms/setMarks/path/basic.js index 2d9513b50..e02e45fe8 100644 --- a/packages/slate/test/transforms/setMarks/path/basic.js +++ b/packages/slate/test/transforms/setMarks/path/basic.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.setMarks(editor, [{ existing: true }], { key: true }, { at: [0, 0] }) + Editor.setMarks(editor, { existing: true }, { key: true }, { at: [0, 0] }) } export const input = ( diff --git a/packages/slate/test/transforms/setMarks/range/basic.js b/packages/slate/test/transforms/setMarks/range/basic.js index fd292e79e..1fe9c6d77 100644 --- a/packages/slate/test/transforms/setMarks/range/basic.js +++ b/packages/slate/test/transforms/setMarks/range/basic.js @@ -6,7 +6,7 @@ import { jsx } from '../../..' export const run = editor => { Editor.setMarks( editor, - [{ key: 'a' }], + { key: 'a' }, { thing: true }, { at: { diff --git a/packages/slate/test/transforms/setMarks/selection/basic.js b/packages/slate/test/transforms/setMarks/selection/basic.js index fd3d56ffe..60ea89f92 100644 --- a/packages/slate/test/transforms/setMarks/selection/basic.js +++ b/packages/slate/test/transforms/setMarks/selection/basic.js @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { jsx } from '../../..' export const run = editor => { - Editor.setMarks(editor, [{ key: 'a' }], { thing: true }) + Editor.setMarks(editor, { key: 'a' }, { thing: true }) } export const input = (