mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-12 10:14:02 +02:00
add ability to not normalize on state creation
This commit is contained in:
@@ -42,10 +42,12 @@ class State extends new Record(DEFAULTS) {
|
|||||||
* Create a new `State` with `properties`.
|
* Create a new `State` with `properties`.
|
||||||
*
|
*
|
||||||
* @param {Object|State} properties
|
* @param {Object|State} properties
|
||||||
|
* @param {Object} options
|
||||||
|
* @property {Boolean} normalize
|
||||||
* @return {State}
|
* @return {State}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static create(properties = {}) {
|
static create(properties = {}, options = {}) {
|
||||||
if (properties instanceof State) return properties
|
if (properties instanceof State) return properties
|
||||||
|
|
||||||
const document = Document.create(properties.document)
|
const document = Document.create(properties.document)
|
||||||
@@ -58,9 +60,9 @@ class State extends new Record(DEFAULTS) {
|
|||||||
|
|
||||||
const state = new State({ document, selection })
|
const state = new State({ document, selection })
|
||||||
|
|
||||||
return state.transform()
|
return options.normalize === false
|
||||||
.normalize(SCHEMA)
|
? state
|
||||||
.apply({ save: false })
|
: state.transform().normalize(SCHEMA).apply({ save: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -182,7 +182,7 @@ const Raw = {
|
|||||||
selection = Raw.deserializeSelection(object.selection, options)
|
selection = Raw.deserializeSelection(object.selection, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
return State.create({ document, selection })
|
return State.create({ document, selection }, options)
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -54,6 +54,31 @@ describe('serializers', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('optionally does not normalize', () => {
|
||||||
|
const html = new Html(require('./fixtures/html/deserialize/inline-with-is-void').default)
|
||||||
|
const input = fs.readFileSync(resolve(__dirname, './fixtures/html/deserialize/inline-with-is-void/input.html'), 'utf8')
|
||||||
|
const serialized = html.deserialize(input, { toRaw: true, normalize: false })
|
||||||
|
assert.deepEqual(serialized, {
|
||||||
|
kind: 'state',
|
||||||
|
document: {
|
||||||
|
kind: 'document',
|
||||||
|
nodes: [
|
||||||
|
{
|
||||||
|
kind: 'block',
|
||||||
|
type: 'paragraph',
|
||||||
|
nodes: [
|
||||||
|
{
|
||||||
|
kind: 'inline',
|
||||||
|
type: 'link',
|
||||||
|
isVoid: true,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('serialize()', () => {
|
describe('serialize()', () => {
|
||||||
|
Reference in New Issue
Block a user