@box/activity-feed 2.2.17 → 2.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Text}from"@box/blueprint-web";import{jsx}from"react/jsx-runtime";function renderTextNode(node,index){return jsx(Text,{as:`span`,variant:`bodyDefault`,children:node.text},index)}function renderParagraphNode(node,index){return!node.content||node.content.length===0?jsx(`br`,{},index):jsx(Text,{as:`p`,variant:`bodyDefault`,color:`textOnLightDefault`,children:node.content.map((textNode,idx)=>renderTextNode(textNode,idx))},index)}function MessageRenderer({messageObject}){return!messageObject||!messageObject.content?null:jsx(`div`,{children:messageObject.content.map((node,idx)=>renderParagraphNode(node,idx))})}export{MessageRenderer};
|
|
1
|
+
import{splitTextIntoSegments}from"./url-segments.js";import{Link,Text}from"@box/blueprint-web";import{jsx}from"react/jsx-runtime";function renderTextNode(node,index){return jsx(Text,{as:`span`,variant:`bodyDefault`,children:splitTextIntoSegments(node.text).map((segment,segmentIndex)=>segment.type===`url`?jsx(Link,{href:segment.value,inheritFont:!0,rel:`noopener noreferrer`,target:`_blank`,children:segment.value},segmentIndex):segment.value)},index)}function renderParagraphNode(node,index){return!node.content||node.content.length===0?jsx(`br`,{},index):jsx(Text,{as:`p`,variant:`bodyDefault`,color:`textOnLightDefault`,children:node.content.map((textNode,idx)=>renderTextNode(textNode,idx))},index)}function MessageRenderer({messageObject}){return!messageObject||!messageObject.content?null:jsx(`div`,{children:messageObject.content.map((node,idx)=>renderParagraphNode(node,idx))})}export{MessageRenderer};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var URL_REGEX=/((?:(?:ht|f)tps?:\/\/)[\w.-]+(?::\d+)?(?:[/?#][\w\-.~+/#?&%=:[\]@!$'()*;,]*)?)/gi,SENTENCE_PUNCTUATION=/[.,;:!?。、!?;:,،؛؟]/,BRACKET_PAIRS={")":`(`,"]":`[`,")":`(`,"】":`【`,"」":`「`,"』":`『`},shouldTrimLastChar=url=>{let lastChar=url[url.length-1];if(SENTENCE_PUNCTUATION.test(lastChar))return!0;let opener=BRACKET_PAIRS[lastChar];if(opener){let openCount=url.split(opener).length-1;return url.split(lastChar).length-1>openCount}return!1},trimTrailingChars=url=>{let trimmed=url;for(;trimmed.length>0&&shouldTrimLastChar(trimmed);)trimmed=trimmed.slice(0,-1);return trimmed},splitTextIntoSegments=text=>{let matches=Array.from(text.matchAll(URL_REGEX)).filter(match=>match.index!==void 0),segments=[],cursor=0;for(let match of matches){let matchStart=match.index,url=trimTrailingChars(match[0]),matchEnd=matchStart+url.length;matchStart>cursor&&segments.push({type:`text`,value:text.slice(cursor,matchStart)}),segments.push({type:`url`,value:url}),cursor=matchEnd}return cursor<text.length&&segments.push({type:`text`,value:text.slice(cursor)}),segments};export{URL_REGEX,splitTextIntoSegments,trimTrailingChars};
|