本文整理汇总了TypeScript中draft-js.CharacterMetadata.create方法的典型用法代码示例。如果您正苦于以下问题:TypeScript CharacterMetadata.create方法的具体用法?TypeScript CharacterMetadata.create怎么用?TypeScript CharacterMetadata.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类draft-js.CharacterMetadata
的用法示例。
在下文中一共展示了CharacterMetadata.create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: ContentBlock
contentBlocks = contentBlocks.reduce(function (contentBlocks, block) {
if (block.getType() !== 'blockquote') {
return contentBlocks.concat(block)
}
const image = JSON.parse(block.getText())
contentState.createEntity('IMAGE-ENTITY', 'IMMUTABLE', image);
const entityKey = contentState.getLastCreatedEntityKey();
const charData = CharacterMetadata.create({ entity: entityKey });
// const blockSpec = Object.assign({ type: 'atomic', text: ' ' }, { entityData })
// const atomicBlock = createContentBlock(blockSpec)
// const spacerBlock = createContentBlock({});
const fragmentArray = [
new ContentBlock({
key: genKey(),
type: 'image-block',
text: ' ',
characterList: List(Repeat(charData, charData.count())),
}),
new ContentBlock({
key: genKey(),
type: 'unstyled',
text: '',
characterList: List(),
}),
];
return contentBlocks.concat(fragmentArray);
}, []);
示例2: genKey
const createContentBlock = ( blockData: DraftEntityInstance, contentState: ContentState) => {
const {key, type, text, data, inlineStyles, entityData} = blockData;
let blockSpec = {
type: type != null ? type : 'unstyled',
text: text != null ? text : '',
key: key != null ? key : genKey(),
data: null,
characterList: List([]),
};
if (data) {
blockSpec.data = fromJS(data)
}
if (inlineStyles || entityData) {
let entityKey;
if (entityData) {
const {type, mutability, data} = entityData;
contentState.createEntity(type, mutability, data);
entityKey = contentState.getLastCreatedEntityKey();
} else {
entityKey = null
}
const style = OrderedSet(inlineStyles || [])
const charData = CharacterMetadata.create({style, entityKey} as CharacterMetadataConfig)
blockSpec.characterList = List(Repeat(charData, text.length))
}
return new ContentBlock(blockSpec)
}
示例3: ContentBlock
const atomicBlock = (data, entity) => new ContentBlock({
key: genKey(), type: 'atomic', text: ' ',
characterList: List([CharacterMetadata.create({entity})]),
data: data,
});