mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-11 01:33:58 +02:00
Operations update decorations (#1778)
* initial simple decorations (mark-like), many tests added * allow decorators to be set by focus, anchor tags - add tests * handle one more edge case with decorations in hyperscript * apply prettier cleanup * apply linting rules * update changelog * ensure always normalize decoration ranges * reapply prettier after latest adjustments * all operations apply now update decorations with selection * ranges can now be 'atomic', will invalidate if contents change * lint, prettier cleanups * add atomic invalidation tests, update hyperscript usage * fix linter errors * minor cleanup * slight refactor for simplicity * remove a couple superfluous lines * update in response to review * drop unnecessarily committed add'l file * remove the need for explicit anchor, focus prop on decoration tags * update hyperscript use to match latest syntax in #1777 * atomic -> isAtomic
This commit is contained in:
committed by
Ian Storm Taylor
parent
63eae6b48b
commit
c500becf81
@@ -19,9 +19,12 @@ const FOCUS = {}
|
||||
*/
|
||||
|
||||
class DecoratorPoint {
|
||||
constructor(key, marks) {
|
||||
constructor({ key, data }, marks) {
|
||||
this._key = key
|
||||
this.marks = marks
|
||||
this.attribs = data || {}
|
||||
this.isAtomic = !!this.attribs.atomic
|
||||
delete this.attribs.atomic
|
||||
return this
|
||||
}
|
||||
withPosition = offset => {
|
||||
@@ -45,6 +48,8 @@ class DecoratorPoint {
|
||||
anchorOffset: this.offset,
|
||||
focusOffset: focus.offset,
|
||||
marks: this.marks,
|
||||
isAtomic: this.isAtomic,
|
||||
...this.attribs,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -97,7 +102,7 @@ const CREATORS = {
|
||||
|
||||
decoration(tagName, attributes, children) {
|
||||
if (attributes.key) {
|
||||
return new DecoratorPoint(attributes.key, [{ type: tagName }])
|
||||
return new DecoratorPoint(attributes, [{ type: tagName }])
|
||||
}
|
||||
|
||||
const nodes = createChildren(children, { key: attributes.key })
|
||||
@@ -106,6 +111,7 @@ const CREATORS = {
|
||||
anchorOffset: 0,
|
||||
focusOffset: nodes.reduce((len, n) => len + n.text.length, 0),
|
||||
marks: [{ type: tagName }],
|
||||
isAtomic: !!attributes.data.atomic,
|
||||
},
|
||||
])
|
||||
return nodes
|
||||
|
Reference in New Issue
Block a user