Render text blocks
This commit is contained in:
parent
ca4db66308
commit
307573830a
15 changed files with 662 additions and 345 deletions
|
@ -2,37 +2,24 @@ const lineHeight = 24;
|
|||
const userListWidth = 200;
|
||||
const smallScreen = 600;
|
||||
|
||||
function findBreakpointsString(text, breakpoints, index) {
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
const char = text.charAt(i);
|
||||
|
||||
if (char === ' ') {
|
||||
breakpoints.push({ end: i + index, next: i + 1 + index });
|
||||
} else if (i !== text.length - 1 && (char === '-' || char === '?')) {
|
||||
breakpoints.push({ end: i + 1 + index, next: i + 1 + index });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function findBreakpoints(text) {
|
||||
export function findBreakpoints(blocks) {
|
||||
const breakpoints = [];
|
||||
let length = 0;
|
||||
|
||||
if (typeof text === 'string') {
|
||||
findBreakpointsString(text, breakpoints, length);
|
||||
length = text.length;
|
||||
} else if (Array.isArray(text)) {
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
const node = text[i];
|
||||
for (let j = 0; j < blocks.length; j++) {
|
||||
const {text} = blocks[j];
|
||||
|
||||
if (typeof node === 'string') {
|
||||
findBreakpointsString(node, breakpoints, length);
|
||||
length += node.length;
|
||||
} else {
|
||||
findBreakpointsString(node.props.children, breakpoints, length);
|
||||
length += node.props.children.length;
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
const char = text.charAt(i);
|
||||
|
||||
if (char === ' ') {
|
||||
breakpoints.push({ end: length + i, next: length + i + 1 });
|
||||
} else if (i !== text.length - 1 && (char === '-' || char === '?')) {
|
||||
breakpoints.push({ end: length + i + 1, next: length + i + 1 });
|
||||
}
|
||||
}
|
||||
|
||||
length += text.length;
|
||||
}
|
||||
|
||||
return [breakpoints, length];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue