本文整理匯總了TypeScript中draft-js.CharacterMetadata.getEntity方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript CharacterMetadata.getEntity方法的具體用法?TypeScript CharacterMetadata.getEntity怎麽用?TypeScript CharacterMetadata.getEntity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類draft-js.CharacterMetadata
的用法示例。
在下文中一共展示了CharacterMetadata.getEntity方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getEntityRanges
export default function getEntityRanges(text: string, charMetaList: CharacterMetaList): Array<EntityRange> {
let charEntity: any = null;
let prevCharEntity: any = null;
let ranges: Array<EntityRange> = [];
let rangeStart = 0;
for (let i = 0, len = text.length; i < len; i++) {
prevCharEntity = charEntity;
let meta: CharacterMetadata = charMetaList.get(i);
charEntity = meta ? meta.getEntity() : null;
if (i > 0 && charEntity !== prevCharEntity) {
ranges.push([
prevCharEntity,
getStyleRanges(
text.slice(rangeStart, i),
charMetaList.slice(rangeStart, i)
),
]);
rangeStart = i;
}
}
ranges.push([
charEntity,
getStyleRanges(
text.slice(rangeStart),
charMetaList.slice(rangeStart)
),
]);
return ranges;
}
示例2: getStyleRanges
return blockMap.map(block => {
let resultText = '<div>';
let closeTag = '</div>';
let lastPosition = 0;
const text = block.getText();
const blockType = block.getType();
const blockRender = customBlockRenderMap.get(blockType);
if (blockRender) {
const element = typeof blockRender.element === 'function' ? blockRender.elementTag || 'div' : 'div';
resultText = `<${element || 'div'} style="${getStyleText(customBlockRenderMap.get(blockType).style || {})}">`;
closeTag = `</${element || 'div'}>`;
}
const charMetaList = block.getCharacterList();
let charEntity = null;
let prevCharEntity = null;
let ranges = [];
let rangeStart = 0;
for (let i = 0, len = text.length; i < len; i++) {
prevCharEntity = charEntity;
let meta: CharacterMetadata = charMetaList.get(i);
charEntity = meta ? meta.getEntity() : null;
if (i > 0 && charEntity !== prevCharEntity) {
ranges.push([
prevCharEntity,
getStyleRanges(
text.slice(rangeStart, i),
charMetaList.slice(rangeStart, i)
),
]);
rangeStart = i;
}
}
ranges.push([
charEntity,
getStyleRanges(
text.slice(rangeStart),
charMetaList.slice(rangeStart)
),
]);
ranges.map(([ entityKey, stylePieces]) => {
let element = DEFAULT_ELEMENT;
const rawContent = stylePieces.map(([text]) => text).join('');
let content = stylePieces.map(([text, styleSet]) => {
let encodedContent = encodeContent(text);
if (styleSet.size) {
let inlineStyle = {};
styleSet.forEach(item => {
if (customStyleMap.hasOwnProperty(item)) {
const currentStyle = customStyleMap[item];
inlineStyle = Object.assign(inlineStyle, currentStyle);
}
});
const customedStyle = customStyleFn(styleSet);
inlineStyle = Object.assign(inlineStyle, customedStyle);
return `<span style="${getStyleText(inlineStyle)}">${encodedContent}</span>`;
}
return `<span>${encodedContent}</span>`;
}).join('');
if (entityKey) {
const entity = contentState.getEntity(entityKey);
const entityData = entity.getData();
if (entityData && entityData.export) {
resultText += entityData.export(content, entityData);
} else {
let HTMLText = '';
toHTMLList.forEach(toHTML => {
const text = toHTML(rawContent, entity, contentState);
if (text) {
HTMLText = text;
}
});
if (HTMLText) { resultText += HTMLText }
}
} else {
resultText += content;
}
});
resultText += closeTag;
return resultText;
}).join('\n');