mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-15 11:44:05 +02:00
Feature/add marks (#1306)
* add required yarnrc config to run yarn run bootstrap * add convience method to add list of marks * remove semicolon * remove yarn rc * change addMarks to simply call addMark for each mark * add required yarnrc config to run yarn run bootstrap * add convience method to add list of marks * remove semicolon * remove yarn rc * change addMarks to simply call addMark for each mark * rename state tag to value tag in test cases
This commit is contained in:
committed by
Ian Storm Taylor
parent
3d925a0561
commit
cfa8cf6834
@@ -72,6 +72,17 @@ Changes.addMark = (change, mark) => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a list of `marks` to the characters in the current selection.
|
||||
*
|
||||
* @param {Change} change
|
||||
* @param {Mark} mark
|
||||
*/
|
||||
|
||||
Changes.addMarks = (change, marks) => {
|
||||
marks.forEach(mark => change.addMark(mark))
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete at the current selection.
|
||||
*
|
||||
|
@@ -47,6 +47,20 @@ Changes.addMarkAtRange = (change, range, mark, options = {}) => {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a list of `marks` to the characters at `range`.
|
||||
*
|
||||
* @param {Change} change
|
||||
* @param {Range} range
|
||||
* @param {Array<Mixed>} mark
|
||||
* @param {Object} options
|
||||
* @property {Boolean} normalize
|
||||
*/
|
||||
|
||||
Changes.addMarksAtRange = (change, range, marks, options = {}) => {
|
||||
marks.forEach(mark => change.addMarkAtRange(range, mark, options))
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete everything in a `range`.
|
||||
*
|
||||
|
@@ -0,0 +1,33 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
export default function (change) {
|
||||
change.addMarks(['bold', 'italic'])
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
wo<anchor />rd
|
||||
</paragraph>
|
||||
<paragraph>
|
||||
an<focus />other
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
wo<anchor /><i><b>rd</b></i>
|
||||
</paragraph>
|
||||
<paragraph>
|
||||
<i><b>an</b></i><focus />other
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
@@ -0,0 +1,37 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
export default function (change) {
|
||||
change.addMarks(['bold', 'italic'])
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<link>wo<anchor />rd</link>
|
||||
</paragraph>
|
||||
<paragraph>
|
||||
<link>an<focus />other</link>
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<link>
|
||||
wo<anchor /><i><b>rd</b></i>
|
||||
</link>
|
||||
</paragraph>
|
||||
<paragraph>
|
||||
<link>
|
||||
<i><b>an</b></i><focus />other
|
||||
</link>
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
@@ -0,0 +1,29 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
export default function (change) {
|
||||
change
|
||||
.addMarks(['bold', 'italic'])
|
||||
.insertText('a')
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<cursor />word
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<i><b>a</b></i><cursor />word
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
@@ -0,0 +1,27 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
export default function (change) {
|
||||
change.addMarks(['bold', 'underline'])
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<anchor /><i>wo<focus />rd</i>
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<anchor /><u><b><i>wo</i></b></u><focus /><i>rd</i>
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
@@ -0,0 +1,27 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
export default function (change) {
|
||||
change.addMarks(['bold', 'italic'])
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<anchor />w<focus />ord
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<anchor /><i><b>w</b></i><focus />ord
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
@@ -0,0 +1,27 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
export default function (change) {
|
||||
change.addMarks(['bold', 'italic'])
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
wor<anchor />d<focus />
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
wor<anchor /><i><b>d</b></i><focus />
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
@@ -0,0 +1,27 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
export default function (change) {
|
||||
change.addMarks(['bold', 'italic'])
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
w<anchor />o<focus />rd
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
w<anchor /><i><b>o</b></i><focus />rd
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
@@ -0,0 +1,27 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
export default function (change) {
|
||||
change.addMarks(['bold', 'italic'])
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<anchor />word<focus />
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<anchor /><i><b>word</b></i><focus />
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
@@ -0,0 +1,41 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
import { Mark } from '../../../..'
|
||||
|
||||
|
||||
export default function (change) {
|
||||
const marks = []
|
||||
|
||||
marks.push(Mark.create({
|
||||
type: 'bold',
|
||||
data: { thing: 'value' }
|
||||
}))
|
||||
marks.push(Mark.create({
|
||||
type: 'italic',
|
||||
data: { thing2: 'value2' }
|
||||
}))
|
||||
|
||||
change.addMarks(marks)
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<anchor />w<focus />ord
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<anchor /><i thing2="value2"><b thing="value">w</b></i><focus />ord
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
@@ -0,0 +1,38 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../../helpers/h'
|
||||
|
||||
export default function (change) {
|
||||
const marks = []
|
||||
|
||||
marks.push({
|
||||
type: 'bold',
|
||||
data: { thing: 'value' }
|
||||
})
|
||||
marks.push({
|
||||
type: 'italic',
|
||||
data: { thing2: 'value2' }
|
||||
})
|
||||
|
||||
change.addMarks(marks)
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<anchor />w<focus />ord
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
<anchor /><i thing2="value2"><b thing="value">w</b></i><focus />ord
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
Reference in New Issue
Block a user